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