For if: Else
Const showpage () { if(current_user) { return renderpage (current_user); Else { return showlogin ();} } Const showpage () { fromnullable (current_user) . Fold (Showlogin, renderpage)}
ConstGetprefs = user + = { if(user.premium) {returnloadprefs (user.preferences)}Else { returndefaultprefs; }}ConstGetprefs = user + =(User.premium? Right (user): Left ('Not Premium'). Map (P=user.preferences). Fold (x=defaultprefs, x=loadprefs (x))
ConstStreetName = user + = { ConstAddress =user.address; if(address) {ConstStreet =Address.street; if(street) {returnStreet.name; } } return 'No Street';} cosnt StreetName= user = =fromnullable (user.address). FlatMap (Address=fromnullable (Address.street)). Map (Street=street.name). Fold (e='No Street', n =N)
const Concatuniq = (x, ys) = { const found = ys.filter (y = y = = = x) [0] return found? ys:ys.concat (x);} const Concatuniq = (x, ys) = = y = = = x) [0// fromnullable Needs value . Fold (() = Ys.concat (x), y = ys)
ConstWrapexamples = Example = = { if(Example.previewpath) {Try{Example.preview=Fs.readfilesync (Example.previewpath)}Catch(e) {}returnexample; }}ConstReadFile = x = TryCatch (() =Readfilesync (x));ConstWrapexample = Example = =Fromnullabel (Exampe.previewpath). FlatMap (ReadFile). Fold (()=example, ex=object.assign ({preview:p}, ex); )
ConstParsedburl = CFG = { Try { Constc =Json.parse (CFG); if(c.url) {returnC.url.match (/..../) } Catch(e) {return NULL } }}ConstParsedburl = CFG =TryCatch (()=json.parse (CFG)). FlatMap (c=fromnullable (C.url)). Fold (e=NULL, U= U.match (/..../) )
[JS Compse] 4. A collection of either examples compared to imperative code