UNPKG

1.05 kBJavaScriptView Raw
1var _curry2 =
2/*#__PURE__*/
3require("./_curry2");
4
5var _xfBase =
6/*#__PURE__*/
7require("./_xfBase");
8
9var XDropLast =
10/*#__PURE__*/
11function () {
12 function XDropLast(n, xf) {
13 this.xf = xf;
14 this.pos = 0;
15 this.full = false;
16 this.acc = new Array(n);
17 }
18
19 XDropLast.prototype['@@transducer/init'] = _xfBase.init;
20
21 XDropLast.prototype['@@transducer/result'] = function (result) {
22 this.acc = null;
23 return this.xf['@@transducer/result'](result);
24 };
25
26 XDropLast.prototype['@@transducer/step'] = function (result, input) {
27 if (this.full) {
28 result = this.xf['@@transducer/step'](result, this.acc[this.pos]);
29 }
30
31 this.store(input);
32 return result;
33 };
34
35 XDropLast.prototype.store = function (input) {
36 this.acc[this.pos] = input;
37 this.pos += 1;
38
39 if (this.pos === this.acc.length) {
40 this.pos = 0;
41 this.full = true;
42 }
43 };
44
45 return XDropLast;
46}();
47
48var _xdropLast =
49/*#__PURE__*/
50_curry2(function _xdropLast(n, xf) {
51 return new XDropLast(n, xf);
52});
53
54module.exports = _xdropLast;
\No newline at end of file