Created
January 7, 2016 23:09
Like _.flow, but also accepts arrays of functions.
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 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