Initial commit
[yaffs-website] / node_modules / grunt-contrib-watch / node_modules / lodash / collection / find.js
1 var baseEach = require('../internal/baseEach'),
2     createFind = require('../internal/createFind');
3
4 /**
5  * Iterates over elements of `collection`, returning the first element
6  * `predicate` returns truthy for. The predicate is bound to `thisArg` and
7  * invoked with three arguments: (value, index|key, collection).
8  *
9  * If a property name is provided for `predicate` the created `_.property`
10  * style callback returns the property value of the given element.
11  *
12  * If a value is also provided for `thisArg` the created `_.matchesProperty`
13  * style callback returns `true` for elements that have a matching property
14  * value, else `false`.
15  *
16  * If an object is provided for `predicate` the created `_.matches` style
17  * callback returns `true` for elements that have the properties of the given
18  * object, else `false`.
19  *
20  * @static
21  * @memberOf _
22  * @alias detect
23  * @category Collection
24  * @param {Array|Object|string} collection The collection to search.
25  * @param {Function|Object|string} [predicate=_.identity] The function invoked
26  *  per iteration.
27  * @param {*} [thisArg] The `this` binding of `predicate`.
28  * @returns {*} Returns the matched element, else `undefined`.
29  * @example
30  *
31  * var users = [
32  *   { 'user': 'barney',  'age': 36, 'active': true },
33  *   { 'user': 'fred',    'age': 40, 'active': false },
34  *   { 'user': 'pebbles', 'age': 1,  'active': true }
35  * ];
36  *
37  * _.result(_.find(users, function(chr) {
38  *   return chr.age < 40;
39  * }), 'user');
40  * // => 'barney'
41  *
42  * // using the `_.matches` callback shorthand
43  * _.result(_.find(users, { 'age': 1, 'active': true }), 'user');
44  * // => 'pebbles'
45  *
46  * // using the `_.matchesProperty` callback shorthand
47  * _.result(_.find(users, 'active', false), 'user');
48  * // => 'fred'
49  *
50  * // using the `_.property` callback shorthand
51  * _.result(_.find(users, 'active'), 'user');
52  * // => 'barney'
53  */
54 var find = createFind(baseEach);
55
56 module.exports = find;