Skip to content

Instantly share code, notes, and snippets.

@SanderElias
Created April 11, 2016 09:03
Show Gist options
  • Save SanderElias/cbe006d09a9c7ddb2080b660061bddeb to your computer and use it in GitHub Desktop.
Save SanderElias/cbe006d09a9c7ddb2080b660061bddeb to your computer and use it in GitHub Desktop.
Some functional helper functions
// 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