mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-02 08:07:50 +00:00
70 lines
1.9 KiB
JavaScript
70 lines
1.9 KiB
JavaScript
/**
|
|
* lodash 3.0.2 (Custom Build) <https://lodash.com/>
|
|
* Build: `lodash modern modularize exports="npm" -o ./`
|
|
* Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
|
|
* Based on Underscore.js 1.7.0 <http://underscorejs.org/LICENSE>
|
|
* Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
|
* Available under MIT license <https://lodash.com/license>
|
|
*/
|
|
var arrayEvery = require('lodash._arrayevery');
|
|
|
|
/** Used as the `TypeError` message for "Functions" methods. */
|
|
var FUNC_ERROR_TEXT = 'Expected a function';
|
|
|
|
/**
|
|
* The base implementation of `_.isFunction` without support for environments
|
|
* with incorrect `typeof` results.
|
|
*
|
|
* @private
|
|
* @param {*} value The value to check.
|
|
* @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
|
|
*/
|
|
function baseIsFunction(value) {
|
|
// Avoid a Chakra JIT bug in compatibility modes of IE 11.
|
|
// See https://github.com/jashkenas/underscore/issues/1621 for more details.
|
|
return typeof value == 'function' || false;
|
|
}
|
|
|
|
/**
|
|
* This method is like `_.flow` except that it creates a function that
|
|
* invokes the provided functions from right to left.
|
|
*
|
|
* @static
|
|
* @memberOf _
|
|
* @alias backflow, compose
|
|
* @category Function
|
|
* @param {...Function} [funcs] Functions to invoke.
|
|
* @returns {Function} Returns the new function.
|
|
* @example
|
|
*
|
|
* function square(n) {
|
|
* return n * n;
|
|
* }
|
|
*
|
|
* var addSquare = _.flowRight(square, _.add);
|
|
* addSquare(1, 2);
|
|
* // => 9
|
|
*/
|
|
function flowRight() {
|
|
var funcs = arguments,
|
|
fromIndex = funcs.length - 1;
|
|
|
|
if (fromIndex < 0) {
|
|
return function() { return arguments[0]; };
|
|
}
|
|
if (!arrayEvery(funcs, baseIsFunction)) {
|
|
throw new TypeError(FUNC_ERROR_TEXT);
|
|
}
|
|
return function() {
|
|
var index = fromIndex,
|
|
result = funcs[index].apply(this, arguments);
|
|
|
|
while (index--) {
|
|
result = funcs[index].call(this, result);
|
|
}
|
|
return result;
|
|
};
|
|
}
|
|
|
|
module.exports = flowRight;
|