Remove baseIteratee and castFunction.

This commit is contained in:
John-David Dalton
2017-01-09 17:17:03 -08:00
parent efcf51c7bf
commit 65654f8f9e
96 changed files with 140 additions and 537 deletions

View File

@@ -1,6 +1,5 @@
/**
* A specialized version of `_.forEach` for arrays without support for
* iteratee shorthands.
* A specialized version of `_.forEach` for arrays.
*
* @private
* @param {Array} [array] The array to iterate over.

View File

@@ -1,6 +1,5 @@
/**
* A specialized version of `_.forEachRight` for arrays without support for
* iteratee shorthands.
* A specialized version of `_.forEachRight` for arrays.
*
* @private
* @param {Array} [array] The array to iterate over.

View File

@@ -1,6 +1,5 @@
/**
* A specialized version of `_.every` for arrays without support for
* iteratee shorthands.
* A specialized version of `_.every` for arrays.
*
* @private
* @param {Array} [array] The array to iterate over.

View File

@@ -1,6 +1,5 @@
/**
* A specialized version of `_.filter` for arrays without support for
* iteratee shorthands.
* A specialized version of `_.filter` for arrays.
*
* @private
* @param {Array} [array] The array to iterate over.

View File

@@ -1,6 +1,5 @@
/**
* A specialized version of `_.map` for arrays without support for iteratee
* shorthands.
* A specialized version of `_.map` for arrays.
*
* @private
* @param {Array} [array] The array to iterate over.

View File

@@ -1,6 +1,5 @@
/**
* A specialized version of `_.reduce` for arrays without support for
* iteratee shorthands.
* A specialized version of `_.reduce` for arrays.
*
* @private
* @param {Array} [array] The array to iterate over.

View File

@@ -1,6 +1,5 @@
/**
* A specialized version of `_.reduceRight` for arrays without support for
* iteratee shorthands.
* A specialized version of `_.reduceRight` for arrays.
*
* @private
* @param {Array} [array] The array to iterate over.

View File

@@ -1,6 +1,5 @@
/**
* A specialized version of `_.some` for arrays without support for iteratee
* shorthands.
* A specialized version of `_.some` for arrays.
*
* @private
* @param {Array} [array] The array to iterate over.

View File

@@ -9,7 +9,7 @@ const LARGE_ARRAY_SIZE = 200;
/**
* The base implementation of methods like `_.difference` without support
* for excluding multiple arrays or iteratee shorthands.
* for excluding multiple arrays.
*
* @private
* @param {Array} array The array to inspect.

View File

@@ -2,7 +2,7 @@ import baseForOwn from './_baseForOwn.js';
import createBaseEach from './_createBaseEach.js';
/**
* The base implementation of `_.forEach` without support for iteratee shorthands.
* The base implementation of `_.forEach`.
*
* @private
* @param {Array|Object} collection The collection to iterate over.

View File

@@ -2,7 +2,7 @@ import baseForOwnRight from './_baseForOwnRight.js';
import createBaseEach from './_createBaseEach.js';
/**
* The base implementation of `_.forEachRight` without support for iteratee shorthands.
* The base implementation of `_.forEachRight`.
*
* @private
* @param {Array|Object} collection The collection to iterate over.

View File

@@ -1,7 +1,7 @@
import baseEach from './_baseEach.js';
/**
* The base implementation of `_.every` without support for iteratee shorthands.
* The base implementation of `_.every`.
*
* @private
* @param {Array|Object} collection The collection to iterate over.

View File

@@ -1,7 +1,7 @@
import baseEach from './_baseEach.js';
/**
* The base implementation of `_.filter` without support for iteratee shorthands.
* The base implementation of `_.filter`.
*
* @private
* @param {Array|Object} collection The collection to iterate over.

View File

@@ -1,6 +1,5 @@
/**
* The base implementation of `_.findIndex` and `_.findLastIndex` without
* support for iteratee shorthands.
* The base implementation of `_.findIndex` and `_.findLastIndex`.
*
* @private
* @param {Array} array The array to inspect.

View File

@@ -1,7 +1,6 @@
/**
* The base implementation of methods like `_.findKey` and `_.findLastKey`,
* without support for iteratee shorthands, which iterates over `collection`
* using `eachFunc`.
* The base implementation of methods like `_.findKey` and `_.findLastKey`
* which iterates over `collection` using `eachFunc`.
*
* @private
* @param {Array|Object} collection The collection to inspect.

View File

@@ -2,7 +2,7 @@ import baseFor from './_baseFor.js';
import keys from './keys.js';
/**
* The base implementation of `_.forOwn` without support for iteratee shorthands.
* The base implementation of `_.forOwn`.
*
* @private
* @param {Object} object The object to iterate over.

View File

@@ -2,7 +2,7 @@ import baseForRight from './_baseForRight.js';
import keys from './keys.js';
/**
* The base implementation of `_.forOwnRight` without support for iteratee shorthands.
* The base implementation of `_.forOwnRight`.
*
* @private
* @param {Object} object The object to iterate over.

View File

@@ -8,8 +8,8 @@ import cacheHas from './_cacheHas.js';
const nativeMin = Math.min;
/**
* The base implementation of methods like `_.intersection`, without support
* for iteratee shorthands, that accepts an array of arrays to inspect.
* The base implementation of methods like `_.intersection` that accepts an
* array of arrays to inspect.
*
* @private
* @param {Array} arrays The arrays to inspect.

View File

@@ -6,7 +6,7 @@ const COMPARE_PARTIAL_FLAG = 1;
const COMPARE_UNORDERED_FLAG = 2;
/**
* The base implementation of `_.isMatch` without support for iteratee shorthands.
* The base implementation of `_.isMatch`.
*
* @private
* @param {Object} object The object to inspect.

View File

@@ -1,31 +0,0 @@
import baseMatches from './_baseMatches.js';
import baseMatchesProperty from './_baseMatchesProperty.js';
import identity from './identity.js';
import isArray from './isArray.js';
import property from './property.js';
/**
* The base implementation of `_.iteratee`.
*
* @private
* @param {*} [value=_.identity] The value to convert to an iteratee.
* @returns {Function} Returns the iteratee.
*/
function baseIteratee(value) {
// Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
// See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
if (typeof value == 'function') {
return value;
}
if (value == null) {
return identity;
}
if (typeof value == 'object') {
return isArray(value)
? baseMatchesProperty(value[0], value[1])
: baseMatches(value);
}
return property(value);
}
export default baseIteratee;

View File

@@ -2,7 +2,7 @@ import baseEach from './_baseEach.js';
import isArrayLike from './isArrayLike.js';
/**
* The base implementation of `_.map` without support for iteratee shorthands.
* The base implementation of `_.map`.
*
* @private
* @param {Array|Object} collection The collection to iterate over.

View File

@@ -1,20 +0,0 @@
import baseSum from './_baseSum.js';
/** Used as references for various `Number` constants. */
const NAN = 0 / 0;
/**
* The base implementation of `_.mean` and `_.meanBy` without support for
* iteratee shorthands.
*
* @private
* @param {Array} array The array to iterate over.
* @param {Function} iteratee The function invoked per iteration.
* @returns {number} Returns the mean.
*/
function baseMean(array, iteratee) {
const length = array == null ? 0 : array.length;
return length ? (baseSum(array, iteratee) / length) : NAN;
}
export default baseMean;

View File

@@ -1,5 +1,4 @@
import arrayMap from './_arrayMap.js';
import baseIteratee from './_baseIteratee.js';
import baseMap from './_baseMap.js';
import baseSortBy from './_baseSortBy.js';
import compareMultiple from './_compareMultiple.js';
@@ -16,7 +15,7 @@ import identity from './identity.js';
*/
function baseOrderBy(collection, iteratees, orders) {
let index = -1;
iteratees = arrayMap(iteratees.length ? iteratees : [identity], value => baseIteratee(value));
iteratees = iteratees.length ? iteratees : [identity];
const result = baseMap(collection, (value, key, collection) => {
const criteria = arrayMap(iteratees, iteratee => iteratee(value));

View File

@@ -3,7 +3,7 @@ import baseSet from './_baseSet.js';
import castPath from './_castPath.js';
/**
* The base implementation of `_.pickBy` without support for iteratee shorthands.
* The base implementation of `_.pickBy`.
*
* @private
* @param {Object} object The source object.

View File

@@ -10,8 +10,7 @@ const arrayProto = Array.prototype;
const splice = arrayProto.splice;
/**
* The base implementation of `_.pullAllBy` without support for iteratee
* shorthands.
* The base implementation of `_.pullAllBy`.
*
* @private
* @param {Array} array The array to modify.

View File

@@ -1,6 +1,6 @@
/**
* The base implementation of `_.reduce` and `_.reduceRight`, without support
* for iteratee shorthands, which iterates over `collection` using `eachFunc`.
* The base implementation of `_.reduce` and `_.reduceRight` which iterates
* over `collection` using `eachFunc`.
*
* @private
* @param {Array|Object} collection The collection to iterate over.

View File

@@ -1,7 +1,7 @@
import baseEach from './_baseEach.js';
/**
* The base implementation of `_.some` without support for iteratee shorthands.
* The base implementation of `_.some`.
*
* @private
* @param {Array|Object} collection The collection to iterate over.

View File

@@ -1,8 +1,7 @@
import eq from './eq.js';
/**
* The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
* support for iteratee shorthands.
* The base implementation of `_.sortedUniq` and `_.sortedUniqBy`.
*
* @private
* @param {Array} array The array to inspect.

View File

@@ -1,6 +1,5 @@
/**
* The base implementation of `_.sum` and `_.sumBy` without support for
* iteratee shorthands.
* The base implementation of `_.sum` and `_.sumBy`.
*
* @private
* @param {Array} array The array to iterate over.

View File

@@ -1,6 +1,5 @@
/**
* The base implementation of `_.times` without support for iteratee shorthands
* or max array length checks.
* The base implementation of `_.times` without support for max array length checks.
*
* @private
* @param {number} n The number of times to invoke `iteratee`.

View File

@@ -9,7 +9,7 @@ import setToArray from './_setToArray.js';
const LARGE_ARRAY_SIZE = 200;
/**
* The base implementation of `_.uniqBy` without support for iteratee shorthands.
* The base implementation of `_.uniqBy`.
*
* @private
* @param {Array} array The array to inspect.

View File

@@ -1,8 +1,7 @@
import baseSlice from './_baseSlice.js';
/**
* The base implementation of methods like `_.dropWhile` and `_.takeWhile`
* without support for iteratee shorthands.
* The base implementation of methods like `_.dropWhile` and `_.takeWhile`.
*
* @private
* @param {Array} array The array to query.

View File

@@ -3,8 +3,8 @@ import baseFlatten from './_baseFlatten.js';
import baseUniq from './_baseUniq.js';
/**
* The base implementation of methods like `_.xor`, without support for
* iteratee shorthands, that accepts an array of arrays to inspect.
* The base implementation of methods like `_.xor` which accepts an array of
* arrays to inspect.
*
* @private
* @param {Array} arrays The arrays to inspect.

View File

@@ -1,14 +0,0 @@
import identity from './identity.js';
/**
* Casts `value` to `identity` if it's not a function.
*
* @private
* @param {*} value The value to inspect.
* @returns {Function} Returns cast function.
*/
function castFunction(value) {
return typeof value == 'function' ? value : identity;
}
export default castFunction;

View File

@@ -1,6 +1,5 @@
import arrayAggregator from './_arrayAggregator.js';
import baseAggregator from './_baseAggregator.js';
import baseIteratee from './_baseIteratee.js';
import isArray from './isArray.js';
/**
@@ -15,7 +14,7 @@ function createAggregator(setter, initializer) {
return (collection, iteratee) => {
const func = isArray(collection) ? arrayAggregator : baseAggregator;
const accumulator = initializer ? initializer() : {};
return func(collection, setter, baseIteratee(iteratee, 2), accumulator);
return func(collection, setter, iteratee, accumulator);
};
}

View File

@@ -1,4 +1,3 @@
import baseIteratee from './_baseIteratee.js';
import isArrayLike from './isArrayLike.js';
import keys from './keys.js';
@@ -14,7 +13,6 @@ function createFind(findIndexFunc) {
let iteratee;
const iterable = Object(collection);
if (!isArrayLike(collection)) {
iteratee = baseIteratee(predicate, 3);
collection = keys(collection);
predicate = key => iteratee(iterable[key], key, iterable);
}

View File

@@ -5,11 +5,10 @@ import baseInverter from './_baseInverter.js';
*
* @private
* @param {Function} setter The function to set accumulator values.
* @param {Function} toIteratee The function to resolve iteratees.
* @returns {Function} Returns the new inverter function.
*/
function createInverter(setter, toIteratee) {
return (object, iteratee) => baseInverter(object, setter, toIteratee(iteratee), {});
function createInverter(setter) {
return (object, iteratee) => baseInverter(object, setter, iteratee, {});
}
export default createInverter;

View File

@@ -1,6 +1,4 @@
import apply from './_apply.js';
import arrayMap from './_arrayMap.js';
import baseIteratee from './_baseIteratee.js';
/**
* Creates a function like `_.over`.
@@ -11,8 +9,7 @@ import baseIteratee from './_baseIteratee.js';
*/
function createOver(arrayFunc) {
return (...iteratees) => {
iteratees = arrayMap(iteratees, iteratee => baseIteratee(iteratee));
return (...args) => {
return function(...args) {
const thisArg = this;
return arrayFunc(iteratees, iteratee => apply(iteratee, thisArg, args));
};

View File

@@ -1,6 +1,5 @@
import apply from './_apply.js';
import arrayMap from './_arrayMap.js';
import baseIteratee from './_baseIteratee.js';
/** Error message constants. */
const FUNC_ERROR_TEXT = 'Expected a function';
@@ -36,13 +35,12 @@ const FUNC_ERROR_TEXT = 'Expected a function';
*/
function cond(pairs) {
const length = pairs == null ? 0 : pairs.length;
const toIteratee = baseIteratee;
pairs = !length ? [] : arrayMap(pairs, pair => {
if (typeof pair[1] != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
return [toIteratee(pair[0]), pair[1]];
return [pair[0], pair[1]];
});
return (...args) => {

View File

@@ -18,16 +18,12 @@ const hasOwnProperty = objectProto.hasOwnProperty;
* @since 0.5.0
* @category Collection
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} [iteratee=_.identity] The iteratee to transform keys.
* @param {Function} iteratee The iteratee to transform keys.
* @returns {Object} Returns the composed aggregate object.
* @example
*
* _.countBy([6.1, 4.2, 6.3], Math.floor);
* // => { '4': 1, '6': 2 }
*
* // The `_.property` iteratee shorthand.
* _.countBy(['one', 'two', 'three'], 'length');
* // => { '3': 2, '5': 1 }
*/
const countBy = createAggregator((result, value, key) => {
if (hasOwnProperty.call(result, key)) {

View File

@@ -1,6 +1,5 @@
import baseDifference from './_baseDifference.js';
import baseFlatten from './_baseFlatten.js';
import baseIteratee from './_baseIteratee.js';
import isArrayLikeObject from './isArrayLikeObject.js';
import last from './last.js';
@@ -19,16 +18,12 @@ import last from './last.js';
* @category Array
* @param {Array} array The array to inspect.
* @param {...Array} [values] The values to exclude.
* @param {Function} [iteratee=_.identity] The iteratee invoked per element.
* @param {Function} iteratee The iteratee invoked per element.
* @returns {Array} Returns the new array of filtered values.
* @example
*
* _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
* // => [1.2]
*
* // The `_.property` iteratee shorthand.
* _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
* // => [{ 'x': 2 }]
*/
function differenceBy(array, ...values) {
let iteratee = last(values);
@@ -36,7 +31,7 @@ function differenceBy(array, ...values) {
iteratee = undefined;
}
return isArrayLikeObject(array)
? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), baseIteratee(iteratee, 2))
? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), iteratee)
: [];
}

View File

@@ -1,4 +1,3 @@
import baseIteratee from './_baseIteratee.js';
import baseWhile from './_baseWhile.js';
/**
@@ -11,7 +10,7 @@ import baseWhile from './_baseWhile.js';
* @since 3.0.0
* @category Array
* @param {Array} array The array to query.
* @param {Function} [predicate=_.identity] The function invoked per iteration.
* @param {Function} predicate The function invoked per iteration.
* @returns {Array} Returns the slice of `array`.
* @example
*
@@ -23,22 +22,10 @@ import baseWhile from './_baseWhile.js';
*
* _.dropRightWhile(users, function(o) { return !o.active; });
* // => objects for ['barney']
*
* // The `_.matches` iteratee shorthand.
* _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
* // => objects for ['barney', 'fred']
*
* // The `_.matchesProperty` iteratee shorthand.
* _.dropRightWhile(users, ['active', false]);
* // => objects for ['barney']
*
* // The `_.property` iteratee shorthand.
* _.dropRightWhile(users, 'active');
* // => objects for ['barney', 'fred', 'pebbles']
*/
function dropRightWhile(array, predicate) {
return (array && array.length)
? baseWhile(array, baseIteratee(predicate, 3), true, true)
? baseWhile(array, predicate, true, true)
: [];
}

View File

@@ -1,4 +1,3 @@
import baseIteratee from './_baseIteratee.js';
import baseWhile from './_baseWhile.js';
/**
@@ -11,7 +10,7 @@ import baseWhile from './_baseWhile.js';
* @since 3.0.0
* @category Array
* @param {Array} array The array to query.
* @param {Function} [predicate=_.identity] The function invoked per iteration.
* @param {Function} predicate The function invoked per iteration.
* @returns {Array} Returns the slice of `array`.
* @example
*
@@ -23,22 +22,10 @@ import baseWhile from './_baseWhile.js';
*
* _.dropWhile(users, function(o) { return !o.active; });
* // => objects for ['pebbles']
*
* // The `_.matches` iteratee shorthand.
* _.dropWhile(users, { 'user': 'barney', 'active': false });
* // => objects for ['fred', 'pebbles']
*
* // The `_.matchesProperty` iteratee shorthand.
* _.dropWhile(users, ['active', false]);
* // => objects for ['pebbles']
*
* // The `_.property` iteratee shorthand.
* _.dropWhile(users, 'active');
* // => objects for ['barney', 'fred', 'pebbles']
*/
function dropWhile(array, predicate) {
return (array && array.length)
? baseWhile(array, baseIteratee(predicate, 3), true)
? baseWhile(array, predicate, true)
: [];
}

View File

@@ -1,6 +1,5 @@
import arrayEvery from './_arrayEvery.js';
import baseEvery from './_baseEvery.js';
import baseIteratee from './_baseIteratee.js';
import isArray from './isArray.js';
import isIterateeCall from './_isIterateeCall.js';
@@ -19,7 +18,7 @@ import isIterateeCall from './_isIterateeCall.js';
* @since 0.1.0
* @category Collection
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} [predicate=_.identity] The function invoked per iteration.
* @param {Function} predicate The function invoked per iteration.
* @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
* @returns {boolean} Returns `true` if all elements pass the predicate check,
* else `false`.
@@ -27,30 +26,13 @@ import isIterateeCall from './_isIterateeCall.js';
*
* _.every([true, 1, null, 'yes'], Boolean);
* // => false
*
* var users = [
* { 'user': 'barney', 'age': 36, 'active': false },
* { 'user': 'fred', 'age': 40, 'active': false }
* ];
*
* // The `_.matches` iteratee shorthand.
* _.every(users, { 'user': 'barney', 'active': false });
* // => false
*
* // The `_.matchesProperty` iteratee shorthand.
* _.every(users, ['active', false]);
* // => true
*
* // The `_.property` iteratee shorthand.
* _.every(users, 'active');
* // => false
*/
function every(collection, predicate, guard) {
const func = isArray(collection) ? arrayEvery : baseEvery;
if (guard && isIterateeCall(collection, predicate, guard)) {
predicate = undefined;
}
return func(collection, baseIteratee(predicate, 3));
return func(collection, predicate);
}
export default every;

View File

@@ -1,6 +1,5 @@
import arrayFilter from './_arrayFilter.js';
import baseFilter from './_baseFilter.js';
import baseIteratee from './_baseIteratee.js';
import isArray from './isArray.js';
/**
@@ -15,7 +14,7 @@ import isArray from './isArray.js';
* @since 0.1.0
* @category Collection
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} [predicate=_.identity] The function invoked per iteration.
* @param {Function} predicate The function invoked per iteration.
* @returns {Array} Returns the new filtered array.
* @see _.reject
* @example
@@ -27,22 +26,10 @@ import isArray from './isArray.js';
*
* _.filter(users, function(o) { return !o.active; });
* // => objects for ['fred']
*
* // The `_.matches` iteratee shorthand.
* _.filter(users, { 'age': 36, 'active': true });
* // => objects for ['barney']
*
* // The `_.matchesProperty` iteratee shorthand.
* _.filter(users, ['active', false]);
* // => objects for ['fred']
*
* // The `_.property` iteratee shorthand.
* _.filter(users, 'active');
* // => objects for ['barney']
*/
function filter(collection, predicate) {
const func = isArray(collection) ? arrayFilter : baseFilter;
return func(collection, baseIteratee(predicate, 3));
return func(collection, predicate);
}
export default filter;

14
find.js
View File

@@ -11,7 +11,7 @@ import findIndex from './findIndex.js';
* @since 0.1.0
* @category Collection
* @param {Array|Object} collection The collection to inspect.
* @param {Function} [predicate=_.identity] The function invoked per iteration.
* @param {Function} predicate The function invoked per iteration.
* @param {number} [fromIndex=0] The index to search from.
* @returns {*} Returns the matched element, else `undefined`.
* @example
@@ -24,18 +24,6 @@ import findIndex from './findIndex.js';
*
* _.find(users, function(o) { return o.age < 40; });
* // => object for 'barney'
*
* // The `_.matches` iteratee shorthand.
* _.find(users, { 'age': 1, 'active': true });
* // => object for 'pebbles'
*
* // The `_.matchesProperty` iteratee shorthand.
* _.find(users, ['active', false]);
* // => object for 'fred'
*
* // The `_.property` iteratee shorthand.
* _.find(users, 'active');
* // => object for 'barney'
*/
const find = createFind(findIndex);

View File

@@ -1,5 +1,4 @@
import baseFindIndex from './_baseFindIndex.js';
import baseIteratee from './_baseIteratee.js';
import toInteger from './toInteger.js';
/* Built-in method references for those with the same name as other `lodash` methods. */
@@ -14,7 +13,7 @@ const nativeMax = Math.max;
* @since 1.1.0
* @category Array
* @param {Array} array The array to inspect.
* @param {Function} [predicate=_.identity] The function invoked per iteration.
* @param {Function} predicate The function invoked per iteration.
* @param {number} [fromIndex=0] The index to search from.
* @returns {number} Returns the index of the found element, else `-1`.
* @example
@@ -27,18 +26,6 @@ const nativeMax = Math.max;
*
* _.findIndex(users, function(o) { return o.user == 'barney'; });
* // => 0
*
* // The `_.matches` iteratee shorthand.
* _.findIndex(users, { 'user': 'fred', 'active': false });
* // => 1
*
* // The `_.matchesProperty` iteratee shorthand.
* _.findIndex(users, ['active', false]);
* // => 0
*
* // The `_.property` iteratee shorthand.
* _.findIndex(users, 'active');
* // => 2
*/
function findIndex(array, predicate, fromIndex) {
const length = array == null ? 0 : array.length;
@@ -49,7 +36,7 @@ function findIndex(array, predicate, fromIndex) {
if (index < 0) {
index = nativeMax(length + index, 0);
}
return baseFindIndex(array, baseIteratee(predicate, 3), index);
return baseFindIndex(array, predicate, index);
}
export default findIndex;

View File

@@ -1,6 +1,5 @@
import baseFindKey from './_baseFindKey.js';
import baseForOwn from './_baseForOwn.js';
import baseIteratee from './_baseIteratee.js';
/**
* This method is like `_.find` except that it returns the key of the first
@@ -11,7 +10,7 @@ import baseIteratee from './_baseIteratee.js';
* @since 1.1.0
* @category Object
* @param {Object} object The object to inspect.
* @param {Function} [predicate=_.identity] The function invoked per iteration.
* @param {Function} predicate The function invoked per iteration.
* @returns {string|undefined} Returns the key of the matched element,
* else `undefined`.
* @example
@@ -24,21 +23,9 @@ import baseIteratee from './_baseIteratee.js';
*
* _.findKey(users, function(o) { return o.age < 40; });
* // => 'barney' (iteration order is not guaranteed)
*
* // The `_.matches` iteratee shorthand.
* _.findKey(users, { 'age': 1, 'active': true });
* // => 'pebbles'
*
* // The `_.matchesProperty` iteratee shorthand.
* _.findKey(users, ['active', false]);
* // => 'fred'
*
* // The `_.property` iteratee shorthand.
* _.findKey(users, 'active');
* // => 'barney'
*/
function findKey(object, predicate) {
return baseFindKey(object, baseIteratee(predicate, 3), baseForOwn);
return baseFindKey(object, predicate, baseForOwn);
}
export default findKey;

View File

@@ -10,7 +10,7 @@ import findLastIndex from './findLastIndex.js';
* @since 2.0.0
* @category Collection
* @param {Array|Object} collection The collection to inspect.
* @param {Function} [predicate=_.identity] The function invoked per iteration.
* @param {Function} predicate The function invoked per iteration.
* @param {number} [fromIndex=collection.length-1] The index to search from.
* @returns {*} Returns the matched element, else `undefined`.
* @example

View File

@@ -1,5 +1,4 @@
import baseFindIndex from './_baseFindIndex.js';
import baseIteratee from './_baseIteratee.js';
import toInteger from './toInteger.js';
/* Built-in method references for those with the same name as other `lodash` methods. */
@@ -15,7 +14,7 @@ const nativeMin = Math.min;
* @since 2.0.0
* @category Array
* @param {Array} array The array to inspect.
* @param {Function} [predicate=_.identity] The function invoked per iteration.
* @param {Function} predicate The function invoked per iteration.
* @param {number} [fromIndex=array.length-1] The index to search from.
* @returns {number} Returns the index of the found element, else `-1`.
* @example
@@ -28,18 +27,6 @@ const nativeMin = Math.min;
*
* _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
* // => 2
*
* // The `_.matches` iteratee shorthand.
* _.findLastIndex(users, { 'user': 'barney', 'active': true });
* // => 0
*
* // The `_.matchesProperty` iteratee shorthand.
* _.findLastIndex(users, ['active', false]);
* // => 2
*
* // The `_.property` iteratee shorthand.
* _.findLastIndex(users, 'active');
* // => 0
*/
function findLastIndex(array, predicate, fromIndex) {
const length = array == null ? 0 : array.length;
@@ -53,7 +40,7 @@ function findLastIndex(array, predicate, fromIndex) {
? nativeMax(length + index, 0)
: nativeMin(index, length - 1);
}
return baseFindIndex(array, baseIteratee(predicate, 3), index, true);
return baseFindIndex(array, predicate, index, true);
}
export default findLastIndex;

View File

@@ -1,6 +1,5 @@
import baseFindKey from './_baseFindKey.js';
import baseForOwnRight from './_baseForOwnRight.js';
import baseIteratee from './_baseIteratee.js';
/**
* This method is like `_.findKey` except that it iterates over elements of
@@ -11,7 +10,7 @@ import baseIteratee from './_baseIteratee.js';
* @since 2.0.0
* @category Object
* @param {Object} object The object to inspect.
* @param {Function} [predicate=_.identity] The function invoked per iteration.
* @param {Function} predicate The function invoked per iteration.
* @returns {string|undefined} Returns the key of the matched element,
* else `undefined`.
* @example
@@ -24,21 +23,9 @@ import baseIteratee from './_baseIteratee.js';
*
* _.findLastKey(users, function(o) { return o.age < 40; });
* // => returns 'pebbles' assuming `_.findKey` returns 'barney'
*
* // The `_.matches` iteratee shorthand.
* _.findLastKey(users, { 'age': 36, 'active': true });
* // => 'barney'
*
* // The `_.matchesProperty` iteratee shorthand.
* _.findLastKey(users, ['active', false]);
* // => 'fred'
*
* // The `_.property` iteratee shorthand.
* _.findLastKey(users, 'active');
* // => 'pebbles'
*/
function findLastKey(object, predicate) {
return baseFindKey(object, baseIteratee(predicate, 3), baseForOwnRight);
return baseFindKey(object, predicate, baseForOwnRight);
}
export default findLastKey;

View File

@@ -11,7 +11,7 @@ import map from './map.js';
* @since 4.0.0
* @category Collection
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array} Returns the new flattened array.
* @example
*

View File

@@ -13,7 +13,7 @@ const INFINITY = 1 / 0;
* @since 4.7.0
* @category Collection
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array} Returns the new flattened array.
* @example
*

View File

@@ -11,7 +11,7 @@ import toInteger from './toInteger.js';
* @since 4.7.0
* @category Collection
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @param {Function} iteratee The function invoked per iteration.
* @param {number} [depth=1] The maximum recursion depth.
* @returns {Array} Returns the new flattened array.
* @example

View File

@@ -1,6 +1,5 @@
import arrayEach from './_arrayEach.js';
import baseEach from './_baseEach.js';
import castFunction from './_castFunction.js';
import baseEach from './_baseEach.js';;
import isArray from './isArray.js';
/**
@@ -18,7 +17,7 @@ import isArray from './isArray.js';
* @alias each
* @category Collection
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array|Object} Returns `collection`.
* @see _.forEachRight
* @example
@@ -35,7 +34,7 @@ import isArray from './isArray.js';
*/
function forEach(collection, iteratee) {
const func = isArray(collection) ? arrayEach : baseEach;
return func(collection, castFunction(iteratee));
return func(collection, iteratee);
}
export default forEach;

View File

@@ -1,6 +1,5 @@
import arrayEachRight from './_arrayEachRight.js';
import baseEachRight from './_baseEachRight.js';
import castFunction from './_castFunction.js';
import isArray from './isArray.js';
/**
@@ -13,7 +12,7 @@ import isArray from './isArray.js';
* @alias eachRight
* @category Collection
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array|Object} Returns `collection`.
* @see _.forEach
* @example
@@ -25,7 +24,7 @@ import isArray from './isArray.js';
*/
function forEachRight(collection, iteratee) {
const func = isArray(collection) ? arrayEachRight : baseEachRight;
return func(collection, castFunction(iteratee));
return func(collection, iteratee);
}
export default forEachRight;

View File

@@ -1,5 +1,4 @@
import baseFor from './_baseFor.js';
import castFunction from './_castFunction.js';
import keysIn from './keysIn.js';
/**
@@ -13,7 +12,7 @@ import keysIn from './keysIn.js';
* @since 0.3.0
* @category Object
* @param {Object} object The object to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Object} Returns `object`.
* @see _.forInRight
* @example
@@ -31,9 +30,7 @@ import keysIn from './keysIn.js';
* // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
*/
function forIn(object, iteratee) {
return object == null
? object
: baseFor(object, castFunction(iteratee), keysIn);
return object == null ? object : baseFor(object, iteratee, keysIn);
}
export default forIn;

View File

@@ -1,5 +1,4 @@
import baseForRight from './_baseForRight.js';
import castFunction from './_castFunction.js';
import keysIn from './keysIn.js';
/**
@@ -11,7 +10,7 @@ import keysIn from './keysIn.js';
* @since 2.0.0
* @category Object
* @param {Object} object The object to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Object} Returns `object`.
* @see _.forIn
* @example
@@ -29,9 +28,7 @@ import keysIn from './keysIn.js';
* // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
*/
function forInRight(object, iteratee) {
return object == null
? object
: baseForRight(object, castFunction(iteratee), keysIn);
return object == null ? object : baseForRight(object, iteratee, keysIn);
}
export default forInRight;

View File

@@ -1,5 +1,4 @@
import baseForOwn from './_baseForOwn.js';
import castFunction from './_castFunction.js';
/**
* Iterates over own enumerable string keyed properties of an object and
@@ -12,7 +11,7 @@ import castFunction from './_castFunction.js';
* @since 0.3.0
* @category Object
* @param {Object} object The object to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Object} Returns `object`.
* @see _.forOwnRight
* @example
@@ -30,7 +29,7 @@ import castFunction from './_castFunction.js';
* // => Logs 'a' then 'b' (iteration order is not guaranteed).
*/
function forOwn(object, iteratee) {
return object && baseForOwn(object, castFunction(iteratee));
return object && baseForOwn(object, iteratee);
}
export default forOwn;

View File

@@ -1,5 +1,4 @@
import baseForOwnRight from './_baseForOwnRight.js';
import castFunction from './_castFunction.js';
/**
* This method is like `_.forOwn` except that it iterates over properties of
@@ -10,7 +9,7 @@ import castFunction from './_castFunction.js';
* @since 2.0.0
* @category Object
* @param {Object} object The object to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Object} Returns `object`.
* @see _.forOwn
* @example
@@ -28,7 +27,7 @@ import castFunction from './_castFunction.js';
* // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
*/
function forOwnRight(object, iteratee) {
return object && baseForOwnRight(object, castFunction(iteratee));
return object && baseForOwnRight(object, iteratee);
}
export default forOwnRight;

View File

@@ -19,16 +19,12 @@ const hasOwnProperty = objectProto.hasOwnProperty;
* @since 0.1.0
* @category Collection
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} [iteratee=_.identity] The iteratee to transform keys.
* @param {Function} iteratee The iteratee to transform keys.
* @returns {Object} Returns the composed aggregate object.
* @example
*
* _.groupBy([6.1, 4.2, 6.3], Math.floor);
* // => { '4': [4.2], '6': [6.1, 6.3] }
*
* // The `_.property` iteratee shorthand.
* _.groupBy(['one', 'two', 'three'], 'length');
* // => { '3': ['one', 'two'], '5': ['three'] }
*/
const groupBy = createAggregator((result, value, key) => {
if (hasOwnProperty.call(result, key)) {

View File

@@ -1,6 +1,5 @@
import arrayMap from './_arrayMap.js';
import baseIntersection from './_baseIntersection.js';
import baseIteratee from './_baseIteratee.js';
import castArrayLikeObject from './_castArrayLikeObject.js';
import last from './last.js';
@@ -16,16 +15,12 @@ import last from './last.js';
* @since 4.0.0
* @category Array
* @param {...Array} [arrays] The arrays to inspect.
* @param {Function} [iteratee=_.identity] The iteratee invoked per element.
* @param {Function} iteratee The iteratee invoked per element.
* @returns {Array} Returns the new array of intersecting values.
* @example
*
* _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
* // => [2.1]
*
* // The `_.property` iteratee shorthand.
* _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
* // => [{ 'x': 1 }]
*/
function intersectionBy(...arrays) {
let iteratee = last(arrays);
@@ -37,7 +32,7 @@ function intersectionBy(...arrays) {
mapped.pop();
}
return (mapped.length && mapped[0] === arrays[0])
? baseIntersection(mapped, baseIteratee(iteratee, 2))
? baseIntersection(mapped, iteratee)
: [];
}

View File

@@ -22,6 +22,6 @@ import identity from './identity.js';
*/
const invert = createInverter((result, value, key) => {
result[value] = key;
}, constant(identity));
});
export default invert;

View File

@@ -1,4 +1,3 @@
import baseIteratee from './_baseIteratee.js';
import createInverter from './_createInverter.js';
/** Used for built-in method references. */
@@ -19,15 +18,12 @@ const hasOwnProperty = objectProto.hasOwnProperty;
* @since 4.1.0
* @category Object
* @param {Object} object The object to invert.
* @param {Function} [iteratee=_.identity] The iteratee invoked per element.
* @param {Function} iteratee The iteratee invoked per element.
* @returns {Object} Returns the new inverted object.
* @example
*
* var object = { 'a': 1, 'b': 2, 'c': 1 };
*
* _.invertBy(object);
* // => { '1': ['a', 'c'], '2': ['b'] }
*
* _.invertBy(object, function(value) {
* return 'group' + value;
* });
@@ -39,6 +35,6 @@ const invertBy = createInverter((result, value, key) => {
} else {
result[value] = [key];
}
}, baseIteratee);
});
export default invertBy;

View File

@@ -12,7 +12,7 @@ import createAggregator from './_createAggregator.js';
* @since 4.0.0
* @category Collection
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} [iteratee=_.identity] The iteratee to transform keys.
* @param {Function} iteratee The iteratee to transform keys.
* @returns {Object} Returns the composed aggregate object.
* @example
*

14
map.js
View File

@@ -1,5 +1,4 @@
import arrayMap from './_arrayMap.js';
import baseIteratee from './_baseIteratee.js';
import baseMap from './_baseMap.js';
import isArray from './isArray.js';
@@ -22,7 +21,7 @@ import isArray from './isArray.js';
* @since 0.1.0
* @category Collection
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array} Returns the new mapped array.
* @example
*
@@ -35,19 +34,10 @@ import isArray from './isArray.js';
*
* _.map({ 'a': 4, 'b': 8 }, square);
* // => [16, 64] (iteration order is not guaranteed)
*
* var users = [
* { 'user': 'barney' },
* { 'user': 'fred' }
* ];
*
* // The `_.property` iteratee shorthand.
* _.map(users, 'user');
* // => ['barney', 'fred']
*/
function map(collection, iteratee) {
const func = isArray(collection) ? arrayMap : baseMap;
return func(collection, baseIteratee(iteratee, 3));
return func(collection, iteratee);
}
export default map;

View File

@@ -1,6 +1,5 @@
import baseAssignValue from './_baseAssignValue.js';
import baseForOwn from './_baseForOwn.js';
import baseIteratee from './_baseIteratee.js';
/**
* The opposite of `_.mapValues`; this method creates an object with the
@@ -13,7 +12,7 @@ import baseIteratee from './_baseIteratee.js';
* @since 3.8.0
* @category Object
* @param {Object} object The object to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Object} Returns the new mapped object.
* @see _.mapValues
* @example
@@ -25,8 +24,6 @@ import baseIteratee from './_baseIteratee.js';
*/
function mapKeys(object, iteratee) {
const result = {};
iteratee = baseIteratee(iteratee, 3);
baseForOwn(object, (value, key, object) => {
baseAssignValue(result, iteratee(value, key, object), value);
});

View File

@@ -1,6 +1,5 @@
import baseAssignValue from './_baseAssignValue.js';
import baseForOwn from './_baseForOwn.js';
import baseIteratee from './_baseIteratee.js';
/**
* Creates an object with the same keys as `object` and values generated
@@ -13,7 +12,7 @@ import baseIteratee from './_baseIteratee.js';
* @since 2.4.0
* @category Object
* @param {Object} object The object to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Object} Returns the new mapped object.
* @see _.mapKeys
* @example
@@ -25,15 +24,9 @@ import baseIteratee from './_baseIteratee.js';
*
* _.mapValues(users, function(o) { return o.age; });
* // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
*
* // The `_.property` iteratee shorthand.
* _.mapValues(users, 'age');
* // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
*/
function mapValues(object, iteratee) {
const result = {};
iteratee = baseIteratee(iteratee, 3);
baseForOwn(object, (value, key, object) => {
baseAssignValue(result, key, iteratee(value, key, object));
});

View File

@@ -1,6 +1,5 @@
import baseExtremum from './_baseExtremum.js';
import baseGt from './_baseGt.js';
import baseIteratee from './_baseIteratee.js';
/**
* This method is like `_.max` except that it accepts `iteratee` which is
@@ -12,7 +11,7 @@ import baseIteratee from './_baseIteratee.js';
* @since 4.0.0
* @category Math
* @param {Array} array The array to iterate over.
* @param {Function} [iteratee=_.identity] The iteratee invoked per element.
* @param {Function} iteratee The iteratee invoked per element.
* @returns {*} Returns the maximum value.
* @example
*
@@ -20,14 +19,10 @@ import baseIteratee from './_baseIteratee.js';
*
* _.maxBy(objects, function(o) { return o.n; });
* // => { 'n': 2 }
*
* // The `_.property` iteratee shorthand.
* _.maxBy(objects, 'n');
* // => { 'n': 2 }
*/
function maxBy(array, iteratee) {
return (array && array.length)
? baseExtremum(array, baseIteratee(iteratee, 2), baseGt)
? baseExtremum(array, iteratee, baseGt)
: undefined;
}

View File

@@ -1,4 +1,4 @@
import baseMean from './_baseMean.js';
import baseMean from './meanBy.js';
import identity from './identity.js';
/**
@@ -16,7 +16,7 @@ import identity from './identity.js';
* // => 5
*/
function mean(array) {
return baseMean(array, identity);
return mean(array, identity);
}
export default mean;

View File

@@ -1,5 +1,7 @@
import baseIteratee from './_baseIteratee.js';
import baseMean from './_baseMean.js';
import baseSum from './_baseSum.js';
/** Used as references for various `Number` constants. */
const NAN = 0 / 0;
/**
* This method is like `_.mean` except that it accepts `iteratee` which is
@@ -11,7 +13,7 @@ import baseMean from './_baseMean.js';
* @since 4.7.0
* @category Math
* @param {Array} array The array to iterate over.
* @param {Function} [iteratee=_.identity] The iteratee invoked per element.
* @param {Function} iteratee The iteratee invoked per element.
* @returns {number} Returns the mean.
* @example
*
@@ -19,13 +21,10 @@ import baseMean from './_baseMean.js';
*
* _.meanBy(objects, function(o) { return o.n; });
* // => 5
*
* // The `_.property` iteratee shorthand.
* _.meanBy(objects, 'n');
* // => 5
*/
function meanBy(array, iteratee) {
return baseMean(array, baseIteratee(iteratee, 2));
const length = array == null ? 0 : array.length;
return length ? (baseSum(array, iteratee) / length) : NAN;
}
export default meanBy;

View File

@@ -1,5 +1,4 @@
import baseExtremum from './_baseExtremum.js';
import baseIteratee from './_baseIteratee.js';
import baseLt from './_baseLt.js';
/**
@@ -12,7 +11,7 @@ import baseLt from './_baseLt.js';
* @since 4.0.0
* @category Math
* @param {Array} array The array to iterate over.
* @param {Function} [iteratee=_.identity] The iteratee invoked per element.
* @param {Function} iteratee The iteratee invoked per element.
* @returns {*} Returns the minimum value.
* @example
*
@@ -20,14 +19,10 @@ import baseLt from './_baseLt.js';
*
* _.minBy(objects, function(o) { return o.n; });
* // => { 'n': 1 }
*
* // The `_.property` iteratee shorthand.
* _.minBy(objects, 'n');
* // => { 'n': 1 }
*/
function minBy(array, iteratee) {
return (array && array.length)
? baseExtremum(array, baseIteratee(iteratee, 2), baseLt)
? baseExtremum(array, iteratee, baseLt)
: undefined;
}

View File

@@ -1,7 +1,5 @@
import apply from './_apply.js';
import arrayMap from './_arrayMap.js';
import baseFlatten from './_baseFlatten.js';
import baseIteratee from './_baseIteratee.js';
/* Built-in method references for those with the same name as other `lodash` methods. */
const nativeMin = Math.min;
@@ -38,7 +36,6 @@ const nativeMin = Math.min;
* // => [100, 10]
*/
function overArgs(func, ...transforms) {
transforms = arrayMap(transforms, transform => baseIteratee(transform));
const funcsLength = transforms.length;
return function(...args) {
let index = -1;

View File

@@ -11,7 +11,7 @@ import createAggregator from './_createAggregator.js';
* @since 3.0.0
* @category Collection
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} [predicate=_.identity] The function invoked per iteration.
* @param {Function} predicate The function invoked per iteration.
* @returns {Array} Returns the array of grouped elements.
* @example
*
@@ -23,18 +23,6 @@ import createAggregator from './_createAggregator.js';
*
* _.partition(users, function(o) { return o.active; });
* // => objects for [['fred'], ['barney', 'pebbles']]
*
* // The `_.matches` iteratee shorthand.
* _.partition(users, { 'age': 1, 'active': false });
* // => objects for [['pebbles'], ['barney', 'fred']]
*
* // The `_.matchesProperty` iteratee shorthand.
* _.partition(users, ['active', false]);
* // => objects for [['barney', 'pebbles'], ['fred']]
*
* // The `_.property` iteratee shorthand.
* _.partition(users, 'active');
* // => objects for [['fred'], ['barney', 'pebbles']]
*/
const partition = createAggregator((result, value, key) =>
result[key ? 0 : 1].push(value), () => [[], []]);

View File

@@ -1,5 +1,4 @@
import arrayMap from './_arrayMap.js';
import baseIteratee from './_baseIteratee.js';
import basePickBy from './_basePickBy.js';
import getAllKeysIn from './_getAllKeysIn.js';
@@ -12,7 +11,7 @@ import getAllKeysIn from './_getAllKeysIn.js';
* @since 4.0.0
* @category Object
* @param {Object} object The source object.
* @param {Function} [predicate=_.identity] The function invoked per property.
* @param {Function} predicate The function invoked per property.
* @returns {Object} Returns the new object.
* @example
*
@@ -26,7 +25,6 @@ function pickBy(object, predicate) {
return {};
}
const props = arrayMap(getAllKeysIn(object), prop => [prop]);
predicate = baseIteratee(predicate);
return basePickBy(object, props, (value, path) => predicate(value, path[0]));
}

View File

@@ -1,4 +1,3 @@
import baseIteratee from './_baseIteratee.js';
import basePullAll from './_basePullAll.js';
/**
@@ -14,7 +13,7 @@ import basePullAll from './_basePullAll.js';
* @category Array
* @param {Array} array The array to modify.
* @param {Array} values The values to remove.
* @param {Function} [iteratee=_.identity] The iteratee invoked per element.
* @param {Function} iteratee The iteratee invoked per element.
* @returns {Array} Returns `array`.
* @example
*
@@ -26,7 +25,7 @@ import basePullAll from './_basePullAll.js';
*/
function pullAllBy(array, values, iteratee) {
return (array && array.length && values && values.length)
? basePullAll(array, values, baseIteratee(iteratee, 2))
? basePullAll(array, values, iteratee)
: array;
}

View File

@@ -1,6 +1,5 @@
import arrayReduce from './_arrayReduce.js';
import baseEach from './_baseEach.js';
import baseIteratee from './_baseIteratee.js';
import baseReduce from './_baseReduce.js';
import isArray from './isArray.js';
@@ -24,7 +23,7 @@ import isArray from './isArray.js';
* @since 0.1.0
* @category Collection
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @param {Function} iteratee The function invoked per iteration.
* @param {*} [accumulator] The initial value.
* @returns {*} Returns the accumulated value.
* @see _.reduceRight
@@ -44,8 +43,7 @@ import isArray from './isArray.js';
function reduce(collection, iteratee, accumulator) {
const func = isArray(collection) ? arrayReduce : baseReduce;
const initAccum = arguments.length < 3;
return func(collection, baseIteratee(iteratee, 4), accumulator, initAccum, baseEach);
return func(collection, iteratee, accumulator, initAccum, baseEach);
}
export default reduce;

View File

@@ -1,6 +1,5 @@
import arrayReduceRight from './_arrayReduceRight.js';
import baseEachRight from './_baseEachRight.js';
import baseIteratee from './_baseIteratee.js';
import baseReduce from './_baseReduce.js';
import isArray from './isArray.js';
@@ -13,7 +12,7 @@ import isArray from './isArray.js';
* @since 0.1.0
* @category Collection
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @param {Function} iteratee The function invoked per iteration.
* @param {*} [accumulator] The initial value.
* @returns {*} Returns the accumulated value.
* @see _.reduce
@@ -29,8 +28,7 @@ import isArray from './isArray.js';
function reduceRight(collection, iteratee, accumulator) {
const func = isArray(collection) ? arrayReduceRight : baseReduce;
const initAccum = arguments.length < 3;
return func(collection, baseIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
return func(collection, iteratee, accumulator, initAccum, baseEachRight);
}
export default reduceRight;

View File

@@ -1,6 +1,5 @@
import arrayFilter from './_arrayFilter.js';
import baseFilter from './_baseFilter.js';
import baseIteratee from './_baseIteratee.js';
import isArray from './isArray.js';
import negate from './negate.js';
@@ -13,7 +12,7 @@ import negate from './negate.js';
* @since 0.1.0
* @category Collection
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} [predicate=_.identity] The function invoked per iteration.
* @param {Function} predicate The function invoked per iteration.
* @returns {Array} Returns the new filtered array.
* @see _.filter
* @example
@@ -25,22 +24,10 @@ import negate from './negate.js';
*
* _.reject(users, function(o) { return !o.active; });
* // => objects for ['fred']
*
* // The `_.matches` iteratee shorthand.
* _.reject(users, { 'age': 40, 'active': true });
* // => objects for ['barney']
*
* // The `_.matchesProperty` iteratee shorthand.
* _.reject(users, ['active', false]);
* // => objects for ['fred']
*
* // The `_.property` iteratee shorthand.
* _.reject(users, 'active');
* // => objects for ['barney']
*/
function reject(collection, predicate) {
const func = isArray(collection) ? arrayFilter : baseFilter;
return func(collection, negate(baseIteratee(predicate, 3)));
return func(collection, negate(predicate));
}
export default reject;

View File

@@ -1,4 +1,3 @@
import baseIteratee from './_baseIteratee.js';
import basePullAt from './_basePullAt.js';
/**
@@ -14,7 +13,7 @@ import basePullAt from './_basePullAt.js';
* @since 2.0.0
* @category Array
* @param {Array} array The array to modify.
* @param {Function} [predicate=_.identity] The function invoked per iteration.
* @param {Function} predicate The function invoked per iteration.
* @returns {Array} Returns the new array of removed elements.
* @example
*
@@ -38,7 +37,6 @@ function remove(array, predicate) {
const indexes = [];
const length = array.length;
predicate = baseIteratee(predicate, 3);
while (++index < length) {
const value = array[index];
if (predicate(value, index, array)) {

22
some.js
View File

@@ -1,5 +1,4 @@
import arraySome from './_arraySome.js';
import baseIteratee from './_baseIteratee.js';
import baseSome from './_baseSome.js';
import isArray from './isArray.js';
import isIterateeCall from './_isIterateeCall.js';
@@ -14,7 +13,7 @@ import isIterateeCall from './_isIterateeCall.js';
* @since 0.1.0
* @category Collection
* @param {Array|Object} collection The collection to iterate over.
* @param {Function} [predicate=_.identity] The function invoked per iteration.
* @param {Function} predicate The function invoked per iteration.
* @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
* @returns {boolean} Returns `true` if any element passes the predicate check,
* else `false`.
@@ -22,30 +21,13 @@ import isIterateeCall from './_isIterateeCall.js';
*
* _.some([null, 0, 'yes', false], Boolean);
* // => true
*
* var users = [
* { 'user': 'barney', 'active': true },
* { 'user': 'fred', 'active': false }
* ];
*
* // The `_.matches` iteratee shorthand.
* _.some(users, { 'user': 'barney', 'active': false });
* // => false
*
* // The `_.matchesProperty` iteratee shorthand.
* _.some(users, ['active', false]);
* // => true
*
* // The `_.property` iteratee shorthand.
* _.some(users, 'active');
* // => true
*/
function some(collection, predicate, guard) {
const func = isArray(collection) ? arraySome : baseSome;
if (guard && isIterateeCall(collection, predicate, guard)) {
predicate = undefined;
}
return func(collection, baseIteratee(predicate, 3));
return func(collection, predicate);
}
export default some;

View File

@@ -1,4 +1,3 @@
import baseIteratee from './_baseIteratee.js';
import baseSortedIndexBy from './_baseSortedIndexBy.js';
/**
@@ -12,7 +11,7 @@ import baseSortedIndexBy from './_baseSortedIndexBy.js';
* @category Array
* @param {Array} array The sorted array to inspect.
* @param {*} value The value to evaluate.
* @param {Function} [iteratee=_.identity] The iteratee invoked per element.
* @param {Function} iteratee The iteratee invoked per element.
* @returns {number} Returns the index at which `value` should be inserted
* into `array`.
* @example
@@ -21,13 +20,9 @@ import baseSortedIndexBy from './_baseSortedIndexBy.js';
*
* _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
* // => 0
*
* // The `_.property` iteratee shorthand.
* _.sortedIndexBy(objects, { 'x': 4 }, 'x');
* // => 0
*/
function sortedIndexBy(array, value, iteratee) {
return baseSortedIndexBy(array, value, baseIteratee(iteratee, 2));
return baseSortedIndexBy(array, value, iteratee);
}
export default sortedIndexBy;

View File

@@ -1,4 +1,3 @@
import baseIteratee from './_baseIteratee.js';
import baseSortedIndexBy from './_baseSortedIndexBy.js';
/**
@@ -12,7 +11,7 @@ import baseSortedIndexBy from './_baseSortedIndexBy.js';
* @category Array
* @param {Array} array The sorted array to inspect.
* @param {*} value The value to evaluate.
* @param {Function} [iteratee=_.identity] The iteratee invoked per element.
* @param {Function} iteratee The iteratee invoked per element.
* @returns {number} Returns the index at which `value` should be inserted
* into `array`.
* @example
@@ -21,13 +20,9 @@ import baseSortedIndexBy from './_baseSortedIndexBy.js';
*
* _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
* // => 1
*
* // The `_.property` iteratee shorthand.
* _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
* // => 1
*/
function sortedLastIndexBy(array, value, iteratee) {
return baseSortedIndexBy(array, value, baseIteratee(iteratee, 2), true);
return baseSortedIndexBy(array, value, iteratee, true);
}
export default sortedLastIndexBy;

View File

@@ -1,4 +1,3 @@
import baseIteratee from './_baseIteratee.js';
import baseSortedUniq from './_baseSortedUniq.js';
/**
@@ -10,7 +9,7 @@ import baseSortedUniq from './_baseSortedUniq.js';
* @since 4.0.0
* @category Array
* @param {Array} array The array to inspect.
* @param {Function} [iteratee] The iteratee invoked per element.
* @param {Function} iteratee The iteratee invoked per element.
* @returns {Array} Returns the new duplicate free array.
* @example
*
@@ -19,7 +18,7 @@ import baseSortedUniq from './_baseSortedUniq.js';
*/
function sortedUniqBy(array, iteratee) {
return (array && array.length)
? baseSortedUniq(array, baseIteratee(iteratee, 2))
? baseSortedUniq(array, iteratee)
: [];
}

View File

@@ -1,4 +1,3 @@
import baseIteratee from './_baseIteratee.js';
import baseSum from './_baseSum.js';
/**
@@ -11,7 +10,7 @@ import baseSum from './_baseSum.js';
* @since 4.0.0
* @category Math
* @param {Array} array The array to iterate over.
* @param {Function} [iteratee=_.identity] The iteratee invoked per element.
* @param {Function} iteratee The iteratee invoked per element.
* @returns {number} Returns the sum.
* @example
*
@@ -19,14 +18,10 @@ import baseSum from './_baseSum.js';
*
* _.sumBy(objects, function(o) { return o.n; });
* // => 20
*
* // The `_.property` iteratee shorthand.
* _.sumBy(objects, 'n');
* // => 20
*/
function sumBy(array, iteratee) {
return (array && array.length)
? baseSum(array, baseIteratee(iteratee, 2))
? baseSum(array, iteratee)
: 0;
}

View File

@@ -1,4 +1,3 @@
import baseIteratee from './_baseIteratee.js';
import baseWhile from './_baseWhile.js';
/**
@@ -11,7 +10,7 @@ import baseWhile from './_baseWhile.js';
* @since 3.0.0
* @category Array
* @param {Array} array The array to query.
* @param {Function} [predicate=_.identity] The function invoked per iteration.
* @param {Function} predicate The function invoked per iteration.
* @returns {Array} Returns the slice of `array`.
* @example
*
@@ -23,22 +22,10 @@ import baseWhile from './_baseWhile.js';
*
* _.takeRightWhile(users, function(o) { return !o.active; });
* // => objects for ['fred', 'pebbles']
*
* // The `_.matches` iteratee shorthand.
* _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
* // => objects for ['pebbles']
*
* // The `_.matchesProperty` iteratee shorthand.
* _.takeRightWhile(users, ['active', false]);
* // => objects for ['fred', 'pebbles']
*
* // The `_.property` iteratee shorthand.
* _.takeRightWhile(users, 'active');
* // => []
*/
function takeRightWhile(array, predicate) {
return (array && array.length)
? baseWhile(array, baseIteratee(predicate, 3), false, true)
? baseWhile(array, predicate, false, true)
: [];
}

View File

@@ -1,4 +1,3 @@
import baseIteratee from './_baseIteratee.js';
import baseWhile from './_baseWhile.js';
/**
@@ -11,7 +10,7 @@ import baseWhile from './_baseWhile.js';
* @since 3.0.0
* @category Array
* @param {Array} array The array to query.
* @param {Function} [predicate=_.identity] The function invoked per iteration.
* @param {Function} predicate The function invoked per iteration.
* @returns {Array} Returns the slice of `array`.
* @example
*
@@ -23,22 +22,10 @@ import baseWhile from './_baseWhile.js';
*
* _.takeWhile(users, function(o) { return !o.active; });
* // => objects for ['barney', 'fred']
*
* // The `_.matches` iteratee shorthand.
* _.takeWhile(users, { 'user': 'barney', 'active': false });
* // => objects for ['barney']
*
* // The `_.matchesProperty` iteratee shorthand.
* _.takeWhile(users, ['active', false]);
* // => objects for ['barney', 'fred']
*
* // The `_.property` iteratee shorthand.
* _.takeWhile(users, 'active');
* // => []
*/
function takeWhile(array, predicate) {
return (array && array.length)
? baseWhile(array, baseIteratee(predicate, 3))
? baseWhile(array, predicate)
: [];
}

View File

@@ -1,5 +1,4 @@
import baseTimes from './_baseTimes.js';
import castFunction from './_castFunction.js';
import toInteger from './toInteger.js';
/** Used as references for various `Number` constants. */
@@ -20,7 +19,7 @@ const nativeMin = Math.min;
* @memberOf _
* @category Util
* @param {number} n The number of times to invoke `iteratee`.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @param {Function} iteratee The function invoked per iteration.
* @returns {Array} Returns the array of results.
* @example
*
@@ -37,11 +36,9 @@ function times(n, iteratee) {
}
let index = MAX_ARRAY_LENGTH;
const length = nativeMin(n, MAX_ARRAY_LENGTH);
iteratee = castFunction(iteratee);
n -= MAX_ARRAY_LENGTH;
const result = baseTimes(length, iteratee);
n -= MAX_ARRAY_LENGTH;
while (++index < n) {
iteratee(index);
}

View File

@@ -1,7 +1,6 @@
import arrayEach from './_arrayEach.js';
import baseCreate from './_baseCreate.js';
import baseForOwn from './_baseForOwn.js';
import baseIteratee from './_baseIteratee.js';
import getPrototype from './_getPrototype.js';
import isArray from './isArray.js';
import isBuffer from './isBuffer.js';
@@ -23,7 +22,7 @@ import isTypedArray from './isTypedArray.js';
* @since 1.3.0
* @category Object
* @param {Object} object The object to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @param {Function} iteratee The function invoked per iteration.
* @param {*} [accumulator] The custom accumulator value.
* @returns {*} Returns the accumulated value.
* @example
@@ -43,7 +42,6 @@ function transform(object, iteratee, accumulator) {
const isArr = isArray(object);
const isArrLike = isArr || isBuffer(object) || isTypedArray(object);
iteratee = baseIteratee(iteratee, 4);
if (accumulator == null) {
const Ctor = object && object.constructor;
if (isArrLike) {

View File

@@ -1,5 +1,4 @@
import baseFlatten from './_baseFlatten.js';
import baseIteratee from './_baseIteratee.js';
import baseUniq from './_baseUniq.js';
import isArrayLikeObject from './isArrayLikeObject.js';
import last from './last.js';
@@ -16,23 +15,19 @@ import last from './last.js';
* @since 4.0.0
* @category Array
* @param {...Array} [arrays] The arrays to inspect.
* @param {Function} [iteratee=_.identity] The iteratee invoked per element.
* @param {Function} iteratee The iteratee invoked per element.
* @returns {Array} Returns the new array of combined values.
* @example
*
* _.unionBy([2.1], [1.2, 2.3], Math.floor);
* // => [2.1, 1.2]
*
* // The `_.property` iteratee shorthand.
* _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
* // => [{ 'x': 1 }, { 'x': 2 }]
*/
function unionBy(...arrays) {
let iteratee = last(arrays);
if (isArrayLikeObject(iteratee)) {
iteratee = undefined;
}
return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), baseIteratee(iteratee, 2));
return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), iteratee);
}
export default unionBy;

View File

@@ -1,4 +1,3 @@
import baseIteratee from './_baseIteratee.js';
import baseUniq from './_baseUniq.js';
/**
@@ -13,19 +12,15 @@ import baseUniq from './_baseUniq.js';
* @since 4.0.0
* @category Array
* @param {Array} array The array to inspect.
* @param {Function} [iteratee=_.identity] The iteratee invoked per element.
* @param {Function} iteratee The iteratee invoked per element.
* @returns {Array} Returns the new duplicate free array.
* @example
*
* _.uniqBy([2.1, 1.2, 2.3], Math.floor);
* // => [2.1, 1.2]
*
* // The `_.property` iteratee shorthand.
* _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
* // => [{ 'x': 1 }, { 'x': 2 }]
*/
function uniqBy(array, iteratee) {
return (array && array.length) ? baseUniq(array, baseIteratee(iteratee, 2)) : [];
return (array && array.length) ? baseUniq(array, iteratee) : [];
}
export default uniqBy;

View File

@@ -12,7 +12,7 @@ import unzip from './unzip.js';
* @since 3.8.0
* @category Array
* @param {Array} array The array of grouped elements to process.
* @param {Function} [iteratee=_.identity] The function to combine
* @param {Function} iteratee The function to combine
* regrouped values.
* @returns {Array} Returns the new array of regrouped elements.
* @example
@@ -28,9 +28,6 @@ function unzipWith(array, iteratee) {
return [];
}
const result = unzip(array);
if (iteratee == null) {
return result;
}
return arrayMap(result, group => apply(iteratee, undefined, group));
}

View File

@@ -1,5 +1,4 @@
import baseUpdate from './_baseUpdate.js';
import castFunction from './_castFunction.js';
/**
* This method is like `_.set` except that accepts `updater` to produce the
@@ -29,7 +28,7 @@ import castFunction from './_castFunction.js';
* // => 0
*/
function update(object, path, updater) {
return object == null ? object : baseUpdate(object, path, castFunction(updater));
return object == null ? object : baseUpdate(object, path, updater);
}
export default update;

View File

@@ -1,5 +1,4 @@
import baseUpdate from './_baseUpdate.js';
import castFunction from './_castFunction.js';
/**
* This method is like `_.update` except that it accepts `customizer` which is
@@ -27,7 +26,7 @@ import castFunction from './_castFunction.js';
*/
function updateWith(object, path, updater, customizer) {
customizer = typeof customizer == 'function' ? customizer : undefined;
return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
return object == null ? object : baseUpdate(object, path, updater, customizer);
}
export default updateWith;

View File

@@ -1,5 +1,4 @@
import arrayFilter from './_arrayFilter.js';
import baseIteratee from './_baseIteratee.js';
import baseXor from './_baseXor.js';
import isArrayLikeObject from './isArrayLikeObject.js';
import last from './last.js';
@@ -16,23 +15,19 @@ import last from './last.js';
* @since 4.0.0
* @category Array
* @param {...Array} [arrays] The arrays to inspect.
* @param {Function} [iteratee=_.identity] The iteratee invoked per element.
* @param {Function} iteratee The iteratee invoked per element.
* @returns {Array} Returns the new array of filtered values.
* @example
*
* _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
* // => [1.2, 3.4]
*
* // The `_.property` iteratee shorthand.
* _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
* // => [{ 'x': 2 }]
*/
function xorBy(...arrays) {
let iteratee = last(arrays);
if (isArrayLikeObject(iteratee)) {
iteratee = undefined;
}
return baseXor(arrayFilter(arrays, isArrayLikeObject), baseIteratee(iteratee, 2));
return baseXor(arrayFilter(arrays, isArrayLikeObject), iteratee);
}
export default xorBy;

View File

@@ -10,7 +10,7 @@ import unzipWith from './unzipWith.js';
* @since 3.8.0
* @category Array
* @param {...Array} [arrays] The arrays to process.
* @param {Function} [iteratee=_.identity] The function to combine
* @param {Function} iteratee The function to combine
* grouped values.
* @returns {Array} Returns the new array of grouped elements.
* @example
@@ -23,7 +23,6 @@ import unzipWith from './unzipWith.js';
function zipWith(...arrays) {
const length = arrays.length;
let iteratee = length > 1 ? arrays[length - 1] : undefined;
iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
return unzipWith(arrays, iteratee);
}