Skip to content

Instantly share code, notes, and snippets.

@gl2748
Last active January 17, 2019 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gl2748/c67475191c998c15396885b76c6860fc to your computer and use it in GitHub Desktop.
Save gl2748/c67475191c998c15396885b76c6860fc to your computer and use it in GitHub Desktop.
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