Created
March 5, 2018 15:04
-
-
Save crshmk/d20c63ab9dce600d5199a5022beda86f to your computer and use it in GitHub Desktop.
A simple pipeline strategy
This file contains hidden or 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
/** | |
* create a pipeline of unary functions | |
* examples at https://github.com/crshmk/pipe/blob/master/index.js | |
*/ | |
let pipe = function() { | |
var fs = Array.prototype.slice.call(arguments); | |
function caller(fs, acc) { | |
return fs.length === 0 ? acc | |
: caller(fs.slice(1), fs[0](acc)); | |
}; | |
return data => caller(fs.slice(1), fs[0](data)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment