1 var baseIteratee = require('./_baseIteratee'),
2 baseWhile = require('./_baseWhile');
5 * Creates a slice of `array` with elements taken from the beginning. Elements
6 * are taken until `predicate` returns falsey. The predicate is invoked with
7 * three arguments: (value, index, array).
13 * @param {Array} array The array to query.
14 * @param {Function} [predicate=_.identity] The function invoked per iteration.
15 * @returns {Array} Returns the slice of `array`.
19 * { 'user': 'barney', 'active': false },
20 * { 'user': 'fred', 'active': false},
21 * { 'user': 'pebbles', 'active': true }
24 * _.takeWhile(users, function(o) { return !o.active; });
25 * // => objects for ['barney', 'fred']
27 * // The `_.matches` iteratee shorthand.
28 * _.takeWhile(users, { 'user': 'barney', 'active': false });
29 * // => objects for ['barney']
31 * // The `_.matchesProperty` iteratee shorthand.
32 * _.takeWhile(users, ['active', false]);
33 * // => objects for ['barney', 'fred']
35 * // The `_.property` iteratee shorthand.
36 * _.takeWhile(users, 'active');
39 function takeWhile(array, predicate) {
40 return (array && array.length)
41 ? baseWhile(array, baseIteratee(predicate, 3))
45 module.exports = takeWhile;