2016-10-11

Javascript monad Maybe with Monet



The Monad Maybe

Maybe aka option or optional is very useful for preventing null. Using the Javascript library Monet it's quite easy to use this monad.

Preventing null

You have a variable but don't know if it's null. With Maybe, you wrap it and test if it is "some".

Transform or map

Monads are also useful to transform a value to another. Think of this example:
Each step is instancing a variable and making a "halt". With a monad, you can "go with the flow" and do it all in one step:

Sample

https://jsfiddle.net/yapdd5xv/15/

Inga kommentarer:

Skicka en kommentar