Skip to content

Instantly share code, notes, and snippets.

@crshmk
Created March 5, 2018 15:04
Show Gist options
  • Save crshmk/d20c63ab9dce600d5199a5022beda86f to your computer and use it in GitHub Desktop.
Save crshmk/d20c63ab9dce600d5199a5022beda86f to your computer and use it in GitHub Desktop.
A simple pipeline strategy
/**
* 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