mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-01 07:47:49 +00:00
Bump to v3.4.0.
This commit is contained in:
@@ -1,8 +1,4 @@
|
||||
import arrayEvery from '../internal/arrayEvery';
|
||||
import baseIsFunction from '../internal/baseIsFunction';
|
||||
|
||||
/** Used as the `TypeError` message for "Functions" methods. */
|
||||
var FUNC_ERROR_TEXT = 'Expected a function';
|
||||
import createComposer from '../internal/createComposer';
|
||||
|
||||
/**
|
||||
* Creates a function that returns the result of invoking the provided
|
||||
@@ -16,37 +12,14 @@ var FUNC_ERROR_TEXT = 'Expected a function';
|
||||
* @returns {Function} Returns the new function.
|
||||
* @example
|
||||
*
|
||||
* function add(x, y) {
|
||||
* return x + y;
|
||||
* }
|
||||
*
|
||||
* function square(n) {
|
||||
* return n * n;
|
||||
* }
|
||||
*
|
||||
* var addSquare = _.flow(add, square);
|
||||
* var addSquare = _.flow(_.add, square);
|
||||
* addSquare(1, 2);
|
||||
* // => 9
|
||||
*/
|
||||
function flow() {
|
||||
var funcs = arguments,
|
||||
length = funcs.length;
|
||||
|
||||
if (!length) {
|
||||
return function() { return arguments[0]; };
|
||||
}
|
||||
if (!arrayEvery(funcs, baseIsFunction)) {
|
||||
throw new TypeError(FUNC_ERROR_TEXT);
|
||||
}
|
||||
return function() {
|
||||
var index = 0,
|
||||
result = funcs[index].apply(this, arguments);
|
||||
|
||||
while (++index < length) {
|
||||
result = funcs[index].call(this, result);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
}
|
||||
var flow = createComposer();
|
||||
|
||||
export default flow;
|
||||
|
||||
Reference in New Issue
Block a user