main
Last change
on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
999 bytes
|
Rev | Line | |
---|
[d24f17c] | 1 | import _xfBase from "./_xfBase.js";
|
---|
| 2 |
|
---|
| 3 | var XDropLast =
|
---|
| 4 | /*#__PURE__*/
|
---|
| 5 | function () {
|
---|
| 6 | function XDropLast(n, xf) {
|
---|
| 7 | if (n <= 0) {
|
---|
| 8 | return xf;
|
---|
| 9 | }
|
---|
| 10 |
|
---|
| 11 | this.xf = xf;
|
---|
| 12 | this.pos = 0;
|
---|
| 13 | this.full = false;
|
---|
| 14 | this.acc = new Array(n);
|
---|
| 15 | }
|
---|
| 16 |
|
---|
| 17 | XDropLast.prototype['@@transducer/init'] = _xfBase.init;
|
---|
| 18 |
|
---|
| 19 | XDropLast.prototype['@@transducer/result'] = function (result) {
|
---|
| 20 | this.acc = null;
|
---|
| 21 | return this.xf['@@transducer/result'](result);
|
---|
| 22 | };
|
---|
| 23 |
|
---|
| 24 | XDropLast.prototype['@@transducer/step'] = function (result, input) {
|
---|
| 25 | if (this.full) {
|
---|
| 26 | result = this.xf['@@transducer/step'](result, this.acc[this.pos]);
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | this.store(input);
|
---|
| 30 | return result;
|
---|
| 31 | };
|
---|
| 32 |
|
---|
| 33 | XDropLast.prototype.store = function (input) {
|
---|
| 34 | this.acc[this.pos] = input;
|
---|
| 35 | this.pos += 1;
|
---|
| 36 |
|
---|
| 37 | if (this.pos === this.acc.length) {
|
---|
| 38 | this.pos = 0;
|
---|
| 39 | this.full = true;
|
---|
| 40 | }
|
---|
| 41 | };
|
---|
| 42 |
|
---|
| 43 | return XDropLast;
|
---|
| 44 | }();
|
---|
| 45 |
|
---|
| 46 | export default function _xdropLast(n) {
|
---|
| 47 | return function (xf) {
|
---|
| 48 | return new XDropLast(n, xf);
|
---|
| 49 | };
|
---|
| 50 | } |
---|
Note:
See
TracBrowser
for help on using the repository browser.