@alcadica/maybe
v1.0.2
Published
An implementation of the maybe monad
Downloads
10
Readme
@alcadica/maybe
Implements the maybe monad
Install
npm install --save @alcadica/maybe
Examples
import maybe from '@alcadica/maybe';
const testObject = {
a: {
b: {
c: {
d: 100,
e: 200,
},
},
},
a1: [
{
b1: [
{
c1: 100
}
]
}
]
}
const d = maybe(testObject, 'a.b.c.d'); // 100
const e = maybe(testObject, 'a.b.c.e'); // 200
const f = maybe(testObject, 'a.b.c.f'); // f does not exists, will return undefined
const f2 = maybe(testObject, 'a.b.c.f', 300); // f does not exists, will return 300 as a fallback
// you can also try to get array values providing an index
const c1 = maybe(testObject, 'a1.0.b1.0.c1'); // will return 100