UNPKG

1.61 kBJavaScriptView Raw
1import arraySome from './_arraySome';
2import baseIteratee from './_baseIteratee';
3import baseSome from './_baseSome';
4import isArray from './isArray';
5import isIterateeCall from './_isIterateeCall';
6
7/**
8 * Checks if `predicate` returns truthy for **any** element of `collection`.
9 * Iteration is stopped once `predicate` returns truthy. The predicate is
10 * invoked with three arguments: (value, index|key, collection).
11 *
12 * @static
13 * @memberOf _
14 * @since 0.1.0
15 * @category Collection
16 * @param {Array|Object} collection The collection to iterate over.
17 * @param {Array|Function|Object|string} [predicate=_.identity]
18 * The function invoked per iteration.
19 * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
20 * @returns {boolean} Returns `true` if any element passes the predicate check,
21 * else `false`.
22 * @example
23 *
24 * _.some([null, 0, 'yes', false], Boolean);
25 * // => true
26 *
27 * var users = [
28 * { 'user': 'barney', 'active': true },
29 * { 'user': 'fred', 'active': false }
30 * ];
31 *
32 * // The `_.matches` iteratee shorthand.
33 * _.some(users, { 'user': 'barney', 'active': false });
34 * // => false
35 *
36 * // The `_.matchesProperty` iteratee shorthand.
37 * _.some(users, ['active', false]);
38 * // => true
39 *
40 * // The `_.property` iteratee shorthand.
41 * _.some(users, 'active');
42 * // => true
43 */
44function some(collection, predicate, guard) {
45 var func = isArray(collection) ? arraySome : baseSome;
46 if (guard && isIterateeCall(collection, predicate, guard)) {
47 predicate = undefined;
48 }
49 return func(collection, baseIteratee(predicate, 3));
50}
51
52export default some;