Skip to content

Instantly share code, notes, and snippets.

@gl2748
Last active Jan 17, 2019
Embed
What would you like to do?
const x = 10
const add = p => q => p + q;
const add1 = add(1)
const add2 = add(2)
// Note that here the accumulating value is itself a function.
const reducer = (acc, curr) => (...args) => {
return curr(acc(...args));
};
const compose = (...fns) => fns.reduce(reducer);
const calc = compose(
add1,
add2
)(x)
// calc = 13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment