Skip to content

Instantly share code, notes, and snippets.

@venomnert
Last active June 30, 2017 23:23
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 venomnert/545fecba3c2dd5a6c05f178f89136a4c to your computer and use it in GitHub Desktop.
Save venomnert/545fecba3c2dd5a6c05f178f89136a4c to your computer and use it in GitHub Desktop.
// Utilize the previous pipe function that accepts only two functions
const _pipe = (a, b) => (arg) => b(a(arg));
// The rest parameters creates an array of operations
const pipe = (...ops) => {
// Iterate over the array of operations
// By using reduce, merge all operations into a single bundle
let bundle = ops.reduce((prevOp, nextOp) => {
return _pipe(prevOp,nextOp);
});
return bundle;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment