From dfd4ae9ea4f0ec88f3b234c29590de872cfde1af Mon Sep 17 00:00:00 2001 From: John-David Dalton Date: Sat, 5 Sep 2015 22:29:38 -0700 Subject: [PATCH] Add `_.modArgsSet`. --- lodash.js | 44 ++++++++++++++++++++++++++++++++++++++++---- test/test.js | 3 ++- 2 files changed, 42 insertions(+), 5 deletions(-) diff --git a/lodash.js b/lodash.js index a045e7c98..5c2e0de1d 100644 --- a/lodash.js +++ b/lodash.js @@ -7600,16 +7600,51 @@ * return [x, y]; * }, square, doubled); * - * modded(3, 4); - * // => [9, 8] + * modded(9, 3); + * // => [81, 6] * - * modded(5, 10); - * // => [25, 20] + * modded(10, 5); + * // => [100, 10] */ var modArgs = createModArgs(function(value) { return [value]; }); + /** + * This method is like `_.modArgs` except that each transform function is + * provided all arguments the created function is invoked with. + * + * @static + * @memberOf _ + * @category Function + * @param {Function} func The function to wrap. + * @param {...(Function|Function[])} [transforms] The functions to transform + * arguments, specified individually or in arrays. + * @returns {Function} Returns the new function. + * @example + * + * function multiply(x, y) { + * return x * y; + * } + * + * function divide(x, y) { + * return x / y; + * } + * + * var modded = _.modArgsSet(function(x, y) { + * return [x, y]; + * }, multiply, divide); + * + * modded(9, 3); + * // => [27, 3] + * + * modded(10, 5); + * // => [50, 2] + */ + var modArgsSet = createModArgs(function(value, index, args) { + return args; + }); + /** * Creates a function that negates the result of the predicate `func`. The * `func` predicate is invoked with the `this` binding and arguments of the @@ -11833,6 +11868,7 @@ lodash.methodOf = methodOf; lodash.mixin = mixin; lodash.modArgs = modArgs; + lodash.modArgsSet = modArgsSet; lodash.negate = negate; lodash.omit = omit; lodash.omitBy = omitBy; diff --git a/test/test.js b/test/test.js index 9e9f407c2..3e71144ac 100644 --- a/test/test.js +++ b/test/test.js @@ -17638,6 +17638,7 @@ 'delay', 'memoize', 'modArgs', + 'modArgsSet', 'negate', 'once', 'partial', @@ -17753,7 +17754,7 @@ }); }); - test('should throw an error for falsey arguments', 23, function() { + test('should throw an error for falsey arguments', 24, function() { _.each(rejectFalsey, function(methodName) { var expected = _.map(falsey, _.constant(true)), func = _[methodName];