_xdropLast.js 999 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import _xfBase from "./_xfBase.js";
  2. var XDropLast =
  3. /*#__PURE__*/
  4. function () {
  5. function XDropLast(n, xf) {
  6. if (n <= 0) {
  7. return xf;
  8. }
  9. this.xf = xf;
  10. this.pos = 0;
  11. this.full = false;
  12. this.acc = new Array(n);
  13. }
  14. XDropLast.prototype['@@transducer/init'] = _xfBase.init;
  15. XDropLast.prototype['@@transducer/result'] = function (result) {
  16. this.acc = null;
  17. return this.xf['@@transducer/result'](result);
  18. };
  19. XDropLast.prototype['@@transducer/step'] = function (result, input) {
  20. if (this.full) {
  21. result = this.xf['@@transducer/step'](result, this.acc[this.pos]);
  22. }
  23. this.store(input);
  24. return result;
  25. };
  26. XDropLast.prototype.store = function (input) {
  27. this.acc[this.pos] = input;
  28. this.pos += 1;
  29. if (this.pos === this.acc.length) {
  30. this.pos = 0;
  31. this.full = true;
  32. }
  33. };
  34. return XDropLast;
  35. }();
  36. export default function _xdropLast(n) {
  37. return function (xf) {
  38. return new XDropLast(n, xf);
  39. };
  40. }