_xaperture.js 1.1 KB

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