_createReduce.js 888 B

12345678910111213141516171819202122232425262728293031
  1. import _isArrayLike from "./_isArrayLike.js";
  2. var symIterator = typeof Symbol !== 'undefined' ? Symbol.iterator : '@@iterator';
  3. export default function _createReduce(arrayReduce, methodReduce, iterableReduce) {
  4. return function _reduce(xf, acc, list) {
  5. if (_isArrayLike(list)) {
  6. return arrayReduce(xf, acc, list);
  7. }
  8. if (list == null) {
  9. return acc;
  10. }
  11. if (typeof list['fantasy-land/reduce'] === 'function') {
  12. return methodReduce(xf, acc, list, 'fantasy-land/reduce');
  13. }
  14. if (list[symIterator] != null) {
  15. return iterableReduce(xf, acc, list[symIterator]());
  16. }
  17. if (typeof list.next === 'function') {
  18. return iterableReduce(xf, acc, list);
  19. }
  20. if (typeof list.reduce === 'function') {
  21. return methodReduce(xf, acc, list, 'reduce');
  22. }
  23. throw new TypeError('reduce: list must be array or iterable');
  24. };
  25. }