couldbe
v1.0.0
Published
Maybe-style monoid.
Downloads
4
Readme
couldbe
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'