sequency
Version:
Functional sequences for processing iterable data in JavaScript
26 lines • 787 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.ElementAt = void 0;
var ElementAt = /** @class */ (function () {
function ElementAt() {
}
/**
* Returns the element at position `index` (zero-based) or throws an error if `index`
* is out of bounds.
*
* @param {number} index
* @returns {T}
*/
ElementAt.prototype.elementAt = function (index) {
var i = 0;
for (var item = this.iterator.next(); !item.done; item = this.iterator.next()) {
if (i === index) {
return item.value;
}
i++;
}
throw new Error("Index out of bounds: " + index);
};
return ElementAt;
}());
exports.ElementAt = ElementAt;
//# sourceMappingURL=elementAt.js.map