Skip to content
This repository has been archived by the owner on Sep 5, 2021. It is now read-only.
/ tiny-maybe Public archive

A tiny point-free implementation of a Maybe ADT

License

Notifications You must be signed in to change notification settings

earthtone/tiny-maybe

Repository files navigation

Tiny Maybe

CI Status

A tiny, point-free implementation of Maybe utilities. Useful for when you want to avoid explicity null checks but don't need a more comprehensive/advanced implementation of an ADT.


Usage

import { compose } from '@earthtone/tiny-compose'
import * as Maybe from '@earthtone/tiny-maybe'
import { isNil } from '@earthtone/tiny-predicates'

const has = prop => obj => obj.hasOwnProperty(prop)
const get = prop => obj => obj[prop]

const safeName = compose(
  Maybe.option('John Smith'),
  Maybe.map(get('name')),
  Maybe.of(has('name'))
)

const name = fetch('http://api.com')
  .then(r => r.json())
  .then(safeName)

Note

This is a faithful fork of Ian Hoffman-Hick's original code. It's strongly recommended that you use something like Crocks or Folktale if you want to use ADTs in your production code.

About

A tiny point-free implementation of a Maybe ADT

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published