_baseIteratee.js 721 B

12345678910111213141516
  1. define(['./identity', './isFunction', './isObject', './isArray', './matcher', './property', './_optimizeCb'], function (identity, isFunction, isObject, isArray, matcher, property, _optimizeCb) {
  2. // An internal function to generate callbacks that can be applied to each
  3. // element in a collection, returning the desired result — either `_.identity`,
  4. // an arbitrary callback, a property matcher, or a property accessor.
  5. function baseIteratee(value, context, argCount) {
  6. if (value == null) return identity;
  7. if (isFunction(value)) return _optimizeCb(value, context, argCount);
  8. if (isObject(value) && !isArray(value)) return matcher(value);
  9. return property(value);
  10. }
  11. return baseIteratee;
  12. });