Skip to content
No description or website provided.
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
test
.gitignore
.travis.yml
README.md
index.js
mabbe.js
package.json
test.html

README.md

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,

Something went wrong with that request. Please try again.