Created
April 18, 2015 20:56
-
-
Save nsluss/41049d1c387e9c19d477 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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