1.0.2 • Published 7 years ago

@alcadica/maybe v1.0.2

Weekly downloads
5
License
-
Repository
-
Last release
7 years ago

@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

Licence

MIT