Created
October 26, 2015 12:49
-
-
Save SeanJM/4f52055bc3fe38fe7e13 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
// A function which which allows you to apply a list of functions (supplied as arguments) to a value. | |
// | |
// Usage: pipe(functions...)(value) | |
// | |
// Example: var getFirstWordLetter = pipe(getFirstWord, getFirstLetter); | |
// getFirstWordLetter('Sean MacIsaac') | |
// -> 'S' | |
function pipe () { | |
var functionList = [].slice.call(arguments); | |
function _init_() { | |
var rest = functionList.slice(1); | |
var value = functionList[0].apply(null, arguments); | |
if (rest.length) { | |
return pipe.apply(null, rest)(value); | |
} | |
return value; | |
} | |
return _init_; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment