UNPKG

iteragain

Version:

Javascript Iterable/Iterator/Generator-function utilities.

31 lines 920 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CachedIterator = void 0; /** * @deprecated Use `SeekableIterator` instead. * @description Caches the values of the input `iterator` into a Map. */ 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; } } exports.CachedIterator = CachedIterator; exports.default = CachedIterator; //# sourceMappingURL=CachedIterator.js.map