couldbe

Maybe-style monoid.


Keywords
monoid, monad, functional
License
MIT
Install
npm install couldbe@1.0.0

Documentation

couldbe Build Status Coverage Status

A Maybe-style monoid for JavaScript.

Usage

Given some arbitrary data, e.g.

const data = {
  id: 1
  content: {
    title: 'hello'
  }
}

Instead of ...

if (data.content)
  data.content.body || 'world'

... do the following:

import couldbe from 'couldbe'

couldbe(data)('content')('title')         === 'hello'
couldbe(data)('content')('body', 'world') === 'world'