Created
April 11, 2016 09:03
-
-
Save SanderElias/cbe006d09a9c7ddb2080b660061bddeb to your computer and use it in GitHub Desktop.
Some functional helper functions
This file contains 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
// Functional helpers, curry and compose | |
function curry(fn, ...args) { | |
let _curry = (args) => args.length < fn.length ? (..._args) => _curry([...args, ..._args]) : fn(...args); | |
return _curry(args); | |
} | |
const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args))); | |
const map = curry((fn, value) => value.map(fn)); | |
const reduce = curry((fn, value) => value.reduce(fn)); | |
// ----- end of functional helpers |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment