Skip to content

Instantly share code, notes, and snippets.

@ccnixon
Created October 10, 2015 16:16
Show Gist options
  • Save ccnixon/ff315521c1cb95aa3f9f to your computer and use it in GitHub Desktop.
Save ccnixon/ff315521c1cb95aa3f9f to your computer and use it in GitHub Desktop.
Compose and Pipe
var compose = function(){
//Your code here
var args = Array.prototype.slice.call(arguments);
return function(val){
return args.reduceRight(function(memo, fn){
return fn(memo);
}, val);
};
};
var pipe = function(){
//Your code here
var args = Array.prototype.slice.call(arguments);
return function(val){
return args.reduce(function(memo, fn){
return fn(memo);
}, val);
};
};
@ccnixon
Copy link
Author

ccnixon commented Oct 10, 2015

Quick reproduction of native compose and pipe in JS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment