UNPKG

maybe-fantasy

Version:

Fantasyland maybe implementation

33 lines (18 loc) 661 B
# maybe-fantasy A fantasyland compliant implementation of the maybe monad. ``` js var maybe = require('../') var log = console.log.bind(console, '=>') var something = maybe.of('Hello ').map(function(v) { return v + 'world!' }) log(something.isSomething()) // => true log(something.value) // => 'Hello world!' var nothing = maybe.nothing('Hello ').map(function(v) { return v + 'world!' }) log(nothing.isSomething()) // => false log(nothing.value) // => null (never use this, it not a value!) ``` Unlike many other "maybe" implementations this is not a currying function that checks for null inputs, but a value representation that can be Nothing.