source: node_modules/ramda/src/internal/_xdropLast.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.0 KB
RevLine 
[d24f17c]1var _xfBase =
2/*#__PURE__*/
3require("./_xfBase.js");
4
5var XDropLast =
6/*#__PURE__*/
7function () {
8 function XDropLast(n, xf) {
9 if (n <= 0) {
10 return xf;
11 }
12
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
48function _xdropLast(n) {
49 return function (xf) {
50 return new XDropLast(n, xf);
51 };
52}
53
54module.exports = _xdropLast;
Note: See TracBrowser for help on using the repository browser.