_baseIteratee.js 764 B

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