maybe-fantasy

Fantasyland maybe implementation

npm install maybe-fantasy
4 downloads in the last week
8 downloads in the last month

maybe-fantasy

A fantasyland compliant implementation of the maybe monad.


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.

npm loves you