Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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