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