1 var baseClone = require('./_baseClone'),
2 baseIteratee = require('./_baseIteratee');
5 * Creates a function that invokes `func` with the arguments of the created
6 * function. If `func` is a property name, the created function returns the
7 * property value for a given element. If `func` is an array or object, the
8 * created function returns `true` for elements that contain the equivalent
9 * source properties, otherwise it returns `false`.
15 * @param {*} [func=_.identity] The value to convert to a callback.
16 * @returns {Function} Returns the callback.
20 * { 'user': 'barney', 'age': 36, 'active': true },
21 * { 'user': 'fred', 'age': 40, 'active': false }
24 * // The `_.matches` iteratee shorthand.
25 * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
26 * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
28 * // The `_.matchesProperty` iteratee shorthand.
29 * _.filter(users, _.iteratee(['user', 'fred']));
30 * // => [{ 'user': 'fred', 'age': 40 }]
32 * // The `_.property` iteratee shorthand.
33 * _.map(users, _.iteratee('user'));
34 * // => ['barney', 'fred']
36 * // Create custom iteratee shorthands.
37 * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
38 * return !_.isRegExp(func) ? iteratee(func) : function(string) {
39 * return func.test(string);
43 * _.filter(['abc', 'def'], /ef/);
46 function iteratee(func) {
47 return baseIteratee(typeof func == 'function' ? func : baseClone(func, true));
50 module.exports = iteratee;