Created
January 7, 2016 23:09
-
-
Save danallison/2e7b6d673d6f52c2bea8 to your computer and use it in GitHub Desktop.
Like _.flow, but also accepts arrays of functions.
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
function flowMap () { | |
var functions = [].slice.call(arguments); // convert arguments to array | |
return function () { | |
var _this = this; // maintain context | |
return functions.reduce(function (args, fn) { | |
// for each function or array of functions, | |
// pass in the previous return value. | |
if (_.isArray(fn)) { | |
return [fn.map(function (_fn) { return _fn.apply(_this, args); })]; | |
} else { | |
return [fn.apply(_this, args)]; | |
} | |
}, arguments)[0]; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment