@alcadica/maybe
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

@alcadica/maybe

Coverage Maintainability

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

Dependencies (0)

    Dev Dependencies (4)

    Package Sidebar

    Install

    npm i @alcadica/maybe

    Weekly Downloads

    2

    Version

    1.0.2

    License

    none

    Unpacked Size

    5.21 kB

    Total Files

    5

    Last publish

    Collaborators

    • npm-alcadica
    • octod