Skip to content

Instantly share code, notes, and snippets.

@Bondifrench
Created May 11, 2017 04:58
Show Gist options
  • Save Bondifrench/04047a596349b925d0f61735b86d469a to your computer and use it in GitHub Desktop.
Save Bondifrench/04047a596349b925d0f61735b86d469a to your computer and use it in GitHub Desktop.
Javascript minimal FP library as declared by @JAForbes
const toMaybe = x => x == null ? [] : x
const fromMaybe = (a, Ma) => Ma.concat( a ).pop()
const Just = x => [x]
const Nothing = []
const isJust = Ma => Ma.length > 0
const T = a => f => f(a)
const I = x => x
const K = a => () => a
const get = k => o => toMaybe(o[k])
const maybe = (b, f) => Ma =>
fromMaybe( b, Ma.map( a => f(a) ))(Ma)
module.exports = {
toMaybe
,fromMaybe
,maybe
,Nothing
,Just
,isJust
,get
,T
,I
,K
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment