1 var baseClone = require('./_baseClone'),
2 baseIteratee = require('./_baseIteratee');
4 /** Used to compose bitmasks for cloning. */
5 var CLONE_DEEP_FLAG = 1;
8 * Creates a function that invokes `func` with the arguments of the created
9 * function. If `func` is a property name, the created function returns the
10 * property value for a given element. If `func` is an array or object, the
11 * created function returns `true` for elements that contain the equivalent
12 * source properties, otherwise it returns `false`.
18 * @param {*} [func=_.identity] The value to convert to a callback.
19 * @returns {Function} Returns the callback.
23 * { 'user': 'barney', 'age': 36, 'active': true },
24 * { 'user': 'fred', 'age': 40, 'active': false }
27 * // The `_.matches` iteratee shorthand.
28 * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
29 * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
31 * // The `_.matchesProperty` iteratee shorthand.
32 * _.filter(users, _.iteratee(['user', 'fred']));
33 * // => [{ 'user': 'fred', 'age': 40 }]
35 * // The `_.property` iteratee shorthand.
36 * _.map(users, _.iteratee('user'));
37 * // => ['barney', 'fred']
39 * // Create custom iteratee shorthands.
40 * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
41 * return !_.isRegExp(func) ? iteratee(func) : function(string) {
42 * return func.test(string);
46 * _.filter(['abc', 'def'], /ef/);
49 function iteratee(func) {
50 return baseIteratee(typeof func == 'function' ? func : baseClone(func, CLONE_DEEP_FLAG));
53 module.exports = iteratee;