Last active
June 30, 2017 23:23
-
-
Save venomnert/545fecba3c2dd5a6c05f178f89136a4c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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