Created
May 11, 2017 04:58
-
-
Save Bondifrench/04047a596349b925d0f61735b86d469a to your computer and use it in GitHub Desktop.
Javascript minimal FP library as declared by @JAForbes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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