iteragain
Version:
Javascript Iterable/Iterator/Generator-function utilities.
27 lines • 773 B
JavaScript
/**
* @deprecated Use `SeekableIterator` instead.
* @description Caches the values of the input `iterator` into a Map.
*/
export class CachedIterator {
constructor(iterator) {
this.iterator = iterator;
this.cache = new Map();
this.i = 0;
this.done = false;
}
[Symbol.iterator]() {
return this;
}
next(...args) {
var _a;
if (this.done)
return { done: true, value: undefined };
const next = this.iterator.next(...args);
if ((this.done = (_a = next.done) !== null && _a !== void 0 ? _a : false))
return next;
this.cache.set(this.i++, next.value);
return next;
}
}
export default CachedIterator;
//# sourceMappingURL=CachedIterator.js.map