Allow _.flow and _.flowRight to accept an array of functions.

This commit is contained in:
John-David Dalton
2015-10-24 08:25:52 -07:00
parent 04879d0fe5
commit 3a0fc24a6a

View File

@@ -3871,23 +3871,26 @@
* @returns {Function} Returns the new flow function.
*/
function createFlow(fromRight) {
return function() {
var wrapper,
length = arguments.length,
index = fromRight ? length : -1,
leftIndex = 0,
funcs = Array(length);
return rest(function(funcs) {
funcs = baseFlatten(funcs);
while ((fromRight ? index-- : ++index < length)) {
var func = funcs[leftIndex++] = arguments[index];
var length = funcs.length,
index = length,
prereq = LodashWrapper.prototype.thru;
if (fromRight) {
funcs.reverse();
}
while (index--) {
var func = funcs[index];
if (typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
if (!wrapper && LodashWrapper.prototype.thru && getFuncName(func) == 'wrapper') {
wrapper = new LodashWrapper([], true);
if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
var wrapper = new LodashWrapper([], true);
}
}
index = wrapper ? -1 : length;
index = wrapper ? index : length;
while (++index < length) {
func = funcs[index];
@@ -3915,7 +3918,7 @@
}
return result;
};
};
});
}
/**