0.0.1 • Published 11 years ago

maybe-fantasy v0.0.1

Weekly downloads
4
License
-
Repository
github
Last release
11 years ago

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.