Skip to content

Instantly share code, notes, and snippets.

@nsluss
Created April 18, 2015 20:56
Show Gist options
  • Save nsluss/41049d1c387e9c19d477 to your computer and use it in GitHub Desktop.
Save nsluss/41049d1c387e9c19d477 to your computer and use it in GitHub Desktop.
'use strict';
var reduceRight = Array.prototype.reduceRight;
var reduce = Array.prototype.reduce;
// (c -> d, b -> c, a -> b...) -> a -> d
var compose = function () {
return reduceRight.bind(arrayify(arguments), applyLeft\
);
};
// (a -> b, b -> c, c -> d...) -> a -> d
var pipe = function(){
return reduce.bind(arrayify(arguments), applyLeft);
};
function arrayify (arrayLike) {
return Array.prototype.slice.call(arrayLike, 0);
}
// a, (a -> a) -> a
function applyLeft (x, fn) {
return fn(x);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment