mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
Add _.conj, _.disj, & _.juxt.
This commit is contained in:
88
lodash.js
88
lodash.js
@@ -3596,6 +3596,25 @@
|
|||||||
return wrapper;
|
return wrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a function like `_.conj`.
|
||||||
|
*
|
||||||
|
* @private
|
||||||
|
* @param {Function} arrayFunc The function to iterate over `iteratees`.
|
||||||
|
* @returns {Function} Returns the new invoker function.
|
||||||
|
*/
|
||||||
|
function createInvoker(arrayFunc) {
|
||||||
|
return restParam(function(iteratees) {
|
||||||
|
iteratees = arrayMap(baseFlatten(iteratees), getIteratee());
|
||||||
|
return restParam(function(args) {
|
||||||
|
var thisArg = this;
|
||||||
|
return arrayFunc(iteratees, function(iteratee) {
|
||||||
|
return iteratee.apply(thisArg, args);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a function like `_.modArgs`.
|
* Creates a function like `_.modArgs`.
|
||||||
*
|
*
|
||||||
@@ -7250,6 +7269,30 @@
|
|||||||
return createWrapper(key, bitmask, object, partials, holders);
|
return createWrapper(key, bitmask, object, partials, holders);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a function that checks if **all** of the `predicates` return
|
||||||
|
* truthy when invoked with the arguments provided to the created function.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @memberOf _
|
||||||
|
* @category Function
|
||||||
|
* @param {Function[]} predicates The predicates to check.
|
||||||
|
* @returns {Function} Returns the new function.
|
||||||
|
* @example
|
||||||
|
*
|
||||||
|
* var conjed = _.conj(Boolean, isFinite);
|
||||||
|
*
|
||||||
|
* conjed('1');
|
||||||
|
* // => true
|
||||||
|
*
|
||||||
|
* conjed(null);
|
||||||
|
* // => false
|
||||||
|
*
|
||||||
|
* conjed(NaN);
|
||||||
|
* // => false
|
||||||
|
*/
|
||||||
|
var conj = createInvoker(arrayEvery);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a function that accepts one or more arguments of `func` that when
|
* Creates a function that accepts one or more arguments of `func` that when
|
||||||
* called either invokes `func` returning its result, if all `func` arguments
|
* called either invokes `func` returning its result, if all `func` arguments
|
||||||
@@ -7553,6 +7596,30 @@
|
|||||||
return baseDelay(func, wait, args);
|
return baseDelay(func, wait, args);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a function that checks if **any** of the `predicates` return
|
||||||
|
* truthy when invoked with the arguments provided to the created function.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @memberOf _
|
||||||
|
* @category Function
|
||||||
|
* @param {Function[]} predicates The predicates to check.
|
||||||
|
* @returns {Function} Returns the new function.
|
||||||
|
* @example
|
||||||
|
*
|
||||||
|
* var disjed = _.disj(Boolean, isFinite);
|
||||||
|
*
|
||||||
|
* disjed('1');
|
||||||
|
* // => true
|
||||||
|
*
|
||||||
|
* disjed(null);
|
||||||
|
* // => true
|
||||||
|
*
|
||||||
|
* disjed(NaN);
|
||||||
|
* // => false
|
||||||
|
*/
|
||||||
|
var disj = createInvoker(arraySome);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a function that invokes `func` with arguments reversed.
|
* Creates a function that invokes `func` with arguments reversed.
|
||||||
*
|
*
|
||||||
@@ -7617,6 +7684,24 @@
|
|||||||
*/
|
*/
|
||||||
var flowRight = createFlow(true);
|
var flowRight = createFlow(true);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a function that invokes `iteratees` with the arguments provided
|
||||||
|
* to the created function and returns their results.
|
||||||
|
*
|
||||||
|
* @static
|
||||||
|
* @memberOf _
|
||||||
|
* @category Function
|
||||||
|
* @param {Function[]} iteratees The iteratees to invoke.
|
||||||
|
* @returns {Function} Returns the new function.
|
||||||
|
* @example
|
||||||
|
*
|
||||||
|
* var juxted = _.juxt(Math.max, Math.min);
|
||||||
|
*
|
||||||
|
* juxted(1, 2, 3, 4);
|
||||||
|
* // => [4, 1]
|
||||||
|
*/
|
||||||
|
var juxt = createInvoker(arrayMap);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a function that memoizes the result of `func`. If `resolver` is
|
* Creates a function that memoizes the result of `func`. If `resolver` is
|
||||||
* provided it determines the cache key for storing the result based on the
|
* provided it determines the cache key for storing the result based on the
|
||||||
@@ -12024,6 +12109,7 @@
|
|||||||
lodash.chain = chain;
|
lodash.chain = chain;
|
||||||
lodash.chunk = chunk;
|
lodash.chunk = chunk;
|
||||||
lodash.compact = compact;
|
lodash.compact = compact;
|
||||||
|
lodash.conj = conj;
|
||||||
lodash.constant = constant;
|
lodash.constant = constant;
|
||||||
lodash.countBy = countBy;
|
lodash.countBy = countBy;
|
||||||
lodash.create = create;
|
lodash.create = create;
|
||||||
@@ -12035,6 +12121,7 @@
|
|||||||
lodash.defer = defer;
|
lodash.defer = defer;
|
||||||
lodash.delay = delay;
|
lodash.delay = delay;
|
||||||
lodash.difference = difference;
|
lodash.difference = difference;
|
||||||
|
lodash.disj = disj;
|
||||||
lodash.drop = drop;
|
lodash.drop = drop;
|
||||||
lodash.dropRight = dropRight;
|
lodash.dropRight = dropRight;
|
||||||
lodash.dropRightWhile = dropRightWhile;
|
lodash.dropRightWhile = dropRightWhile;
|
||||||
@@ -12055,6 +12142,7 @@
|
|||||||
lodash.invert = invert;
|
lodash.invert = invert;
|
||||||
lodash.invoke = invoke;
|
lodash.invoke = invoke;
|
||||||
lodash.iteratee = iteratee;
|
lodash.iteratee = iteratee;
|
||||||
|
lodash.juxt = juxt;
|
||||||
lodash.keyBy = keyBy;
|
lodash.keyBy = keyBy;
|
||||||
lodash.keys = keys;
|
lodash.keys = keys;
|
||||||
lodash.keysIn = keysIn;
|
lodash.keysIn = keysIn;
|
||||||
|
|||||||
@@ -20952,7 +20952,7 @@
|
|||||||
var acceptFalsey = _.difference(allMethods, rejectFalsey);
|
var acceptFalsey = _.difference(allMethods, rejectFalsey);
|
||||||
|
|
||||||
QUnit.test('should accept falsey arguments', function(assert) {
|
QUnit.test('should accept falsey arguments', function(assert) {
|
||||||
assert.expect(235);
|
assert.expect(238);
|
||||||
|
|
||||||
var emptyArrays = _.map(falsey, _.constant([]));
|
var emptyArrays = _.map(falsey, _.constant([]));
|
||||||
|
|
||||||
@@ -21023,7 +21023,7 @@
|
|||||||
func = _[methodName];
|
func = _[methodName];
|
||||||
|
|
||||||
var actual = _.map(falsey, function(value, index) {
|
var actual = _.map(falsey, function(value, index) {
|
||||||
var pass = !index && /^(?:backflow|compose|flow(Right)?)$/.test(methodName);
|
var pass = !index && /^(?:backflow|compose|conj|disj|flow(Right)?)$/.test(methodName);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
index ? func(value) : func();
|
index ? func(value) : func();
|
||||||
|
|||||||
Reference in New Issue
Block a user