_xfindIndex.js 887 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import _reduced from "./_reduced.js";
  2. import _xfBase from "./_xfBase.js";
  3. var XFindIndex =
  4. /*#__PURE__*/
  5. function () {
  6. function XFindIndex(f, xf) {
  7. this.xf = xf;
  8. this.f = f;
  9. this.idx = -1;
  10. this.found = false;
  11. }
  12. XFindIndex.prototype['@@transducer/init'] = _xfBase.init;
  13. XFindIndex.prototype['@@transducer/result'] = function (result) {
  14. if (!this.found) {
  15. result = this.xf['@@transducer/step'](result, -1);
  16. }
  17. return this.xf['@@transducer/result'](result);
  18. };
  19. XFindIndex.prototype['@@transducer/step'] = function (result, input) {
  20. this.idx += 1;
  21. if (this.f(input)) {
  22. this.found = true;
  23. result = _reduced(this.xf['@@transducer/step'](result, this.idx));
  24. }
  25. return result;
  26. };
  27. return XFindIndex;
  28. }();
  29. export default function _xfindIndex(f) {
  30. return function (xf) {
  31. return new XFindIndex(f, xf);
  32. };
  33. }