* Creates a `_.flow` or `_.flowRight` function. * * @private * @param {boolean} [fromRight] Specify iterating from right to left. * @returns {Function} Returns the new flow function.
(fromRight)
| 12811 | * @returns {Function} Returns the new flow function. |
| 12812 | */ |
| 12813 | function createFlow(fromRight) { |
| 12814 | return flatRest(function(funcs) { |
| 12815 | var length = funcs.length, |
| 12816 | index = length, |
| 12817 | prereq = LodashWrapper.prototype.thru; |
| 12818 | |
| 12819 | if (fromRight) { |
| 12820 | funcs.reverse(); |
| 12821 | } |
| 12822 | while (index--) { |
| 12823 | var func = funcs[index]; |
| 12824 | if (typeof func != 'function') { |
| 12825 | throw new TypeError(FUNC_ERROR_TEXT); |
| 12826 | } |
| 12827 | if (prereq && !wrapper && getFuncName(func) == 'wrapper') { |
| 12828 | var wrapper = new LodashWrapper([], true); |
| 12829 | } |
| 12830 | } |
| 12831 | index = wrapper ? index : length; |
| 12832 | while (++index < length) { |
| 12833 | func = funcs[index]; |
| 12834 | |
| 12835 | var funcName = getFuncName(func), |
| 12836 | data = funcName == 'wrapper' ? getData(func) : undefined; |
| 12837 | |
| 12838 | if (data && isLaziable(data[0]) && |
| 12839 | data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) && |
| 12840 | !data[4].length && data[9] == 1 |
| 12841 | ) { |
| 12842 | wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]); |
| 12843 | } else { |
| 12844 | wrapper = (func.length == 1 && isLaziable(func)) |
| 12845 | ? wrapper[funcName]() |
| 12846 | : wrapper.thru(func); |
| 12847 | } |
| 12848 | } |
| 12849 | return function() { |
| 12850 | var args = arguments, |
| 12851 | value = args[0]; |
| 12852 | |
| 12853 | if (wrapper && args.length == 1 && isArray(value)) { |
| 12854 | return wrapper.plant(value).value(); |
| 12855 | } |
| 12856 | var index = 0, |
| 12857 | result = length ? funcs[index].apply(this, args) : value; |
| 12858 | |
| 12859 | while (++index < length) { |
| 12860 | result = funcs[index].call(this, result); |
| 12861 | } |
| 12862 | return result; |
| 12863 | }; |
| 12864 | }); |
| 12865 | } |
| 12866 | |
| 12867 | /** |
| 12868 | * Creates a function that wraps `func` to invoke it with optional `this` |
no test coverage detected