iteragain
Version:
Javascript Iterable/Iterator/Generator-function utilities.
22 lines • 683 B
JavaScript
/** An iterator that only yields values beginning from `start` (inclusive) and ending at `end` (exclusive). */
export class SliceIterator {
constructor(iterator, start, end = Infinity) {
this.iterator = iterator;
this.start = start;
this.end = end;
this.i = 0;
}
[Symbol.iterator]() {
return this;
}
next(...args) {
let result;
while (!(result = this.iterator.next(...args)).done && this.i++ < this.start)
;
if (this.i <= this.end)
return result;
return { done: true, value: undefined };
}
}
export default SliceIterator;
//# sourceMappingURL=SliceIterator.js.map