Skip to content

Instantly share code, notes, and snippets.

@medric
Created September 28, 2017 01:27
Show Gist options
  • Select an option

  • Save medric/04b7a4ff2f4ff344d05f9171b70026c4 to your computer and use it in GitHub Desktop.

Select an option

Save medric/04b7a4ff2f4ff344d05f9171b70026c4 to your computer and use it in GitHub Desktop.
/**
* Turns a group of functions into one unique callable function
*/
function compose(...funcs) {
const length = funcs.length;
if (length === 0) {
return arg => arg
}
if (length === 1) {
return funcs[0];
}
return funcs.reduce((a, b) => (...args) => a(b(...args)));
}
export default compose;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment