_baseIteratee.js 804 B

1234567891011121314151617181920
  1. var identity = require('./identity.js');
  2. var isFunction = require('./isFunction.js');
  3. var isObject = require('./isObject.js');
  4. var isArray = require('./isArray.js');
  5. var matcher = require('./matcher.js');
  6. var property = require('./property.js');
  7. var _optimizeCb = require('./_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. 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. }
  17. module.exports = baseIteratee;