1 var arraySome = require('../internal/arraySome'),
2 baseCallback = require('../internal/baseCallback'),
3 baseSome = require('../internal/baseSome'),
4 isArray = require('../lang/isArray'),
5 isIterateeCall = require('../internal/isIterateeCall');
8 * Checks if `predicate` returns truthy for **any** element of `collection`.
9 * The function returns as soon as it finds a passing value and does not iterate
10 * over the entire collection. The predicate is bound to `thisArg` and invoked
11 * with three arguments: (value, index|key, collection).
13 * If a property name is provided for `predicate` the created `_.property`
14 * style callback returns the property value of the given element.
16 * If a value is also provided for `thisArg` the created `_.matchesProperty`
17 * style callback returns `true` for elements that have a matching property
18 * value, else `false`.
20 * If an object is provided for `predicate` the created `_.matches` style
21 * callback returns `true` for elements that have the properties of the given
22 * object, else `false`.
27 * @category Collection
28 * @param {Array|Object|string} collection The collection to iterate over.
29 * @param {Function|Object|string} [predicate=_.identity] The function invoked
31 * @param {*} [thisArg] The `this` binding of `predicate`.
32 * @returns {boolean} Returns `true` if any element passes the predicate check,
36 * _.some([null, 0, 'yes', false], Boolean);
40 * { 'user': 'barney', 'active': true },
41 * { 'user': 'fred', 'active': false }
44 * // using the `_.matches` callback shorthand
45 * _.some(users, { 'user': 'barney', 'active': false });
48 * // using the `_.matchesProperty` callback shorthand
49 * _.some(users, 'active', false);
52 * // using the `_.property` callback shorthand
53 * _.some(users, 'active');
56 function some(collection, predicate, thisArg) {
57 var func = isArray(collection) ? arraySome : baseSome;
58 if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
59 predicate = undefined;
61 if (typeof predicate != 'function' || thisArg !== undefined) {
62 predicate = baseCallback(predicate, thisArg, 3);
64 return func(collection, predicate);
67 module.exports = some;