Skip to content

Instantly share code, notes, and snippets.

@daniel-williams
Created October 27, 2015 00:57
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 daniel-williams/19001ec646922038960b to your computer and use it in GitHub Desktop.
Save daniel-williams/19001ec646922038960b to your computer and use it in GitHub Desktop.
Compose and Sequence
var compose = function () {
var fns = arguments;
return function (result) {
for (var i = fns.length - 1; i > -1; i--) {
result = fns[i].call(this, result);
}
return result;
};
};
// or perhaps
function compose() {
var fns = [].slice.call(arguments);
return function(val) {
return fns.reduceRight(function(acc, fn) {
return fn.call(this, acc);
}, val);
};
}
var flip() {
return [].slice.call(arguments).reverse();
}
var sequence = flip(compose)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment