Created
April 20, 2017 12:18
-
-
Save bravelincy/9d137329fecaf34f6e8eaeb95560c28c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function pipe() { | |
let funcs = arguments; | |
return function() { | |
let length = funcs.length; | |
let index = 0; | |
let result; | |
while (index < length) { | |
let fn = funcs[index]; | |
result = index ? fn.call(null, result) : fn.apply(null, arguments) | |
index++; | |
} | |
return result; | |
} | |
} | |
function compose() { | |
return pipe.apply(null, [].reverse.call(arguments)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment