data-forge
Version:
JavaScript data transformation and analysis toolkit inspired by Pandas and LINQ.
35 lines • 1.22 kB
JavaScript
"use strict";
//
// An iterator that iterates the elements of an iterable multiple times.
// Implementation similar to https://numpy.org/doc/stable/reference/generated/numpy.repeat.html
//
Object.defineProperty(exports, "__esModule", { value: true });
var RepeatIterator = /** @class */ (function () {
function RepeatIterator(iterable, count) {
this.repetition = 0;
this.iterator = iterable[Symbol.iterator]();
this.count = count;
this.result = this.iterator.next();
}
RepeatIterator.prototype.next = function () {
if (this.count == 0) {
return { done: true };
}
if (this.repetition == this.count) {
this.result = this.iterator.next();
this.repetition = 0;
}
this.repetition += 1;
if (this.result.done) {
// https://github.com/Microsoft/TypeScript/issues/8938
return { done: true }; // <= explicit cast here!;
}
return {
done: false,
value: this.result.value
};
};
return RepeatIterator;
}());
exports.RepeatIterator = RepeatIterator;
//# sourceMappingURL=repeat-iterator.js.map