UNPKG

986 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3class SliceIterator {
4 /**
5 * @param {Iterator<T>} source Source Iterator
6 * @param {number} start Zero-based positive start index, inclusive
7 * @param {number} end Zero-based positive end index, exclusive, defaults to end of iterator
8 */
9 constructor(source, start, end = Infinity) {
10 this.source = source;
11 this.start = start;
12 this.end = end;
13 this.i = 0;
14 }
15 next() {
16 // Skip elements before start
17 while (this.i < this.start) {
18 const result = this.source.next();
19 if (result.done) {
20 return result;
21 }
22 this.i++;
23 }
24 // Finish when end is reached
25 this.i++;
26 if (this.i >= this.end) {
27 return { done: true };
28 }
29 return this.source.next();
30 }
31}
32exports.SliceIterator = SliceIterator;
33//# sourceMappingURL=slice.js.map
\No newline at end of file