1 var baseCallback = require('../internal/baseCallback'),
2 baseWhile = require('../internal/baseWhile');
5 * Creates a slice of `array` with elements taken from the beginning. Elements
6 * are taken until `predicate` returns falsey. The predicate is bound to
7 * `thisArg` and invoked with three arguments: (value, index, array).
9 * If a property name is provided for `predicate` the created `_.property`
10 * style callback returns the property value of the given element.
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`.
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`.
23 * @param {Array} array The array to query.
24 * @param {Function|Object|string} [predicate=_.identity] The function invoked
26 * @param {*} [thisArg] The `this` binding of `predicate`.
27 * @returns {Array} Returns the slice of `array`.
30 * _.takeWhile([1, 2, 3], function(n) {
36 * { 'user': 'barney', 'active': false },
37 * { 'user': 'fred', 'active': false},
38 * { 'user': 'pebbles', 'active': true }
41 * // using the `_.matches` callback shorthand
42 * _.pluck(_.takeWhile(users, { 'user': 'barney', 'active': false }), 'user');
45 * // using the `_.matchesProperty` callback shorthand
46 * _.pluck(_.takeWhile(users, 'active', false), 'user');
47 * // => ['barney', 'fred']
49 * // using the `_.property` callback shorthand
50 * _.pluck(_.takeWhile(users, 'active'), 'user');
53 function takeWhile(array, predicate, thisArg) {
54 return (array && array.length)
55 ? baseWhile(array, baseCallback(predicate, thisArg, 3))
59 module.exports = takeWhile;