linqcontainers
Version:
Linq-Collections (ES5): [IEnumerable, IQueryable, ...] + [List, Dictionary, Stack, ... + readonly]
47 lines (46 loc) • 1.35 kB
JavaScript
/*
* Created by Ivan Sanz (@isc30)
* Copyright © 2017 Ivan Sanz Carasa. All rights reserved.
*/
Object.defineProperty(exports, "__esModule", { value: true });
/* ES6 compatibility layer :D
interface IteratorResult<T>
{
done: boolean;
value: T;
}
interface Iterator<T>
{
next(value?: any): IteratorResult<T>;
return?(value?: any): IteratorResult<T>;
throw?(e?: any): IteratorResult<T>;
}*/
var ArrayIterator = /** @class */ (function () {
function ArrayIterator(source) {
this.source = source;
this.reset();
}
ArrayIterator.prototype.copy = function () {
return new ArrayIterator(this.source);
};
ArrayIterator.prototype.reset = function () {
this._index = -1;
};
ArrayIterator.prototype.isValidIndex = function () {
return this._index >= 0 && this._index < this.source.length;
};
ArrayIterator.prototype.next = function () {
++this._index;
return this.isValidIndex();
};
ArrayIterator.prototype.value = function () {
if (!this.isValidIndex()) {
throw new Error("Out of bounds");
}
return this.source[this._index];
};
return ArrayIterator;
}());
exports.ArrayIterator = ArrayIterator;
//# sourceMappingURL=Iterators.js.map
;