1.2.0 • Published 5 years ago

@shards/maybe v1.2.0

Weekly downloads
6
License
MIT
Repository
github
Last release
5 years ago

Maybe

Maybe is a simple module to help make your javascript more declarative.

installation

for npm:

npm i @shards/maybe

for yarn:

yarn add @shards/maybe

to require:

const Maybe = require('@shards/maybe').default

to import (es6 modules):

import Maybe from '@shards/maybe'

for node:

import Maybe from '@shards/maybe/dist/maybe.node.js'

usage

By using a Maybe value, it forces us to handle both the cases where a value does exist, and where it doesn't. This is helpful for dealing with API's that return null/undefined values if they fail.

const list = [
  1,
  2,
  3,
]

const value = list.find(v => v === 4)

Maybe(value).match(
  // just callback
  (v) => {
    console.log(`we found a value: ${v}`)
  },
  // nothing callback
  () => {
    console.log('unable to find value :(')
  },
)
1.2.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago