Maybs
My take on a maybe monad for JavaScript after reading this. It may or may not actually be correct, but it is useful.
Maybs works by providing a wrapping a value, and providing methods to access its properties. It's handy for digging deep into an object without making null checks along the way.
var maybe = ; var val = aValue: aNestedValue: 123 { return a + b; }; value;// >> { aNestedValue: 123 } value;// >> 123 ;// >> 3 ;// >> 3 value// >> undefined
#get(key)
Returns a new Maybe
wrapper for the value's key (or nothing).
#call(key, arg1, arg2...)
Tries to call valuekey and returns the result wrapped in a new Maybe
.
#apply(key, [arg1, arg2...])
Tries to call valuekey and returns the result wrapped in a new Maybe
.
value()
Unwrap the Maybe
, returns the value or undefined
.