Skip to content

Instantly share code, notes, and snippets.

@aSapien
Last active October 8, 2017 16:31
Show Gist options
  • Save aSapien/4154bc7dcc324b6662904bc80b4436e6 to your computer and use it in GitHub Desktop.
Save aSapien/4154bc7dcc324b6662904bc80b4436e6 to your computer and use it in GitHub Desktop.
A small utility function to compose functions, lazily evaluated
function compose(func, ...funcs) {
return function(...args) {
return funcs.length > 0
? compose(...funcs)(func(...args))
: func(...args)
}
}
// Or, in a more compact version:
const compose = (func, ...funcs) => (...args) =>
funcs.length > 0 ? compose(...funcs)(func(...args)) : func(...args);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment