Skip to content

Instantly share code, notes, and snippets.

@obouchari
Created January 10, 2018 22:43
Show Gist options
  • Save obouchari/bd93edade4ad9af787428859f20f906d to your computer and use it in GitHub Desktop.
Save obouchari/bd93edade4ad9af787428859f20f906d to your computer and use it in GitHub Desktop.
FP pipe and compose util functions in ES2015
// Pipe
const pipe = (...fns) =>
(...input) =>
fns.reduce(function(input, fn) {
if (typeof fn !== 'function') {
throw Error(`expect a "function" instead got "${typeof fn}".`);
}
return fn(...[].concat(input));
}, input);
// Compose
const compose = (...fns) => pipe(...fns.reverse());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment