Add _.modArgsSet.

This commit is contained in:
John-David Dalton
2015-09-05 22:29:38 -07:00
parent 5c9585b2b0
commit dfd4ae9ea4
2 changed files with 42 additions and 5 deletions

View File

@@ -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;

View File

@@ -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];