Last active
August 29, 2015 14:02
-
-
Save timruffles/3b0c2d81d11c94922b37 to your computer and use it in GitHub Desktop.
pipe - it's more readable than compose
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
// compose functions left to right, | |
// more readable than 'compose' | |
// => pipe(parseInt,Math.sqrt)("64.928") | |
// 8 | |
function pipe() { | |
var fns = arguments; | |
return function() { | |
var value = arguments; | |
for(var i = 0; i < fns.length; i++) { | |
value = [fns[i].apply(null,value)]; | |
} | |
return value[0]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment