sequency
Version:
Functional sequences for processing iterable data in JavaScript
39 lines • 1.15 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.WithIndex = void 0;
var Sequence_1 = require("./Sequence");
var IndexIterator = /** @class */ (function () {
function IndexIterator(iterator) {
this.iterator = iterator;
this.index = -1;
}
IndexIterator.prototype.next = function (value) {
var item = this.iterator.next();
if (item.done) {
return { done: true, value: undefined };
}
this.index++;
return {
done: false,
value: {
index: this.index,
value: item.value
}
};
};
return IndexIterator;
}());
var WithIndex = /** @class */ (function () {
function WithIndex() {
}
/**
* Returns a new sequence consisting of indexed values for all original elements.
*
* @returns {Sequence<IndexedValue<T>>}
*/
WithIndex.prototype.withIndex = function () {
return (0, Sequence_1.createSequence)(new IndexIterator(this.iterator));
};
return WithIndex;
}());
exports.WithIndex = WithIndex;
//# sourceMappingURL=withIndex.js.map