mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
Allow _.modArgs to accept an array of transforms.
This commit is contained in:
@@ -8036,7 +8036,8 @@
|
|||||||
* @memberOf _
|
* @memberOf _
|
||||||
* @category Function
|
* @category Function
|
||||||
* @param {Function} func The function to wrap.
|
* @param {Function} func The function to wrap.
|
||||||
* @param {...Function} [transforms] The function to transform the corresponding argument.
|
* @param {...(Function|Function[])} [transforms] The functions to transform
|
||||||
|
* arguments, specified as individual functions or arrays of functions.
|
||||||
* @returns {Function} Returns the new function.
|
* @returns {Function} Returns the new function.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
@@ -8059,6 +8060,7 @@
|
|||||||
* // => [25, 20]
|
* // => [25, 20]
|
||||||
*/
|
*/
|
||||||
var modArgs = restParam(function(func, transforms) {
|
var modArgs = restParam(function(func, transforms) {
|
||||||
|
transforms = baseFlatten(transforms);
|
||||||
if (typeof func != 'function' || !arrayEvery(transforms, baseIsFunction)) {
|
if (typeof func != 'function' || !arrayEvery(transforms, baseIsFunction)) {
|
||||||
throw new TypeError(FUNC_ERROR_TEXT);
|
throw new TypeError(FUNC_ERROR_TEXT);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11306,6 +11306,11 @@
|
|||||||
deepEqual(modded(5, 10), [10, 100]);
|
deepEqual(modded(5, 10), [10, 100]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should flatten transforms', 1, function() {
|
||||||
|
var modded = _.modArgs(fn, [doubled, square]);
|
||||||
|
deepEqual(modded(5, 10), [10, 100]);
|
||||||
|
});
|
||||||
|
|
||||||
test('should not transform any argument greater than the number of transforms', 1, function() {
|
test('should not transform any argument greater than the number of transforms', 1, function() {
|
||||||
var modded = _.modArgs(fn, doubled, square);
|
var modded = _.modArgs(fn, doubled, square);
|
||||||
deepEqual(modded(5, 10, 18), [10, 100, 18]);
|
deepEqual(modded(5, 10, 18), [10, 100, 18]);
|
||||||
|
|||||||
Reference in New Issue
Block a user