mabbe

0.0.2 • Public • Published

mabbe is (yet another) Haskell: Maybe and Scala: Option for JS

... works in node.js and on the browser.

Build Status

Download or npm install mabbe

Example

  var option = require('mabbe')

  var parsedQuery = option(req.param.id)
    .map(function(q) { return { _id: new ObjectId(q) }})
    .orElse(option(req.query.query).map(JSON.parse))
    .getOrElse({})

API

Construct

  var option = require('mabbe')

  option('pow')         // Some('pow')
  option.some('pow')    // Some('pow')
  option(0)             // Some(0)

  option(undefined)     // None
  option(null)          // None
  option.none           // None

Use

.exists // true || false
.val // value || undefined
.get() // value || undefined
.map(fn)
.filter(fn)
.flatMap(fn)
.pluck(string) e.g. mabbe({ a: { b: 'c' } } }).pluck('a') or .pluck('a.b')
.each(fn)
.getOrElse(defaultValue)
.getOrFail(errorMessage)
.ortElse(fn || mabbe)
.either(fnForSome, fnForNone)
.toArray() // [value] || undefined

For more usage, see tests

Enjoy,

Readme

Keywords

none

Package Sidebar

Install

npm i mabbe

Weekly Downloads

1

Version

0.0.2

License

none

Last publish

Collaborators

  • mtkopone