From 3a0fc24a6a3bfc6071172098498dcd6d9d10b958 Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 24 Oct 2015 08:25:52 -0700 Subject: [PATCH] Allow `_.flow` and `_.flowRight` to accept an array of functions. --- lodash.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/lodash.js b/lodash.js index 650ecbee0..af94b50a0 100644 --- a/lodash.js +++ b/lodash.js @@ -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; }; - }; + }); } /**