ix
Version:
The Interactive Extensions for JavaScript
45 lines (43 loc) • 1.42 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.repeat = exports.RepeatIterable = void 0;
const iterablex_js_1 = require("../iterablex.js");
/** @ignore */
class RepeatIterable extends iterablex_js_1.IterableX {
constructor(source, count) {
super();
this._source = source;
this._count = count;
}
*[Symbol.iterator]() {
if (this._count === -1) {
while (1) {
for (const item of this._source) {
yield item;
}
}
}
else {
for (let i = 0; i < this._count; i++) {
for (const item of this._source) {
yield item;
}
}
}
}
}
exports.RepeatIterable = RepeatIterable;
/**
* Repeats the async-enumerable sequence a specified number of times.
*
* @template TSource The type of the elements in the source sequence.
* @param {number} [count=-1] Number of times to repeat the sequence. If not specified, the sequence repeats indefinitely.
* @returns {MonoTypeOperatorFunction<TSource>} The iterable sequence producing the elements of the given sequence repeatedly.
*/
function repeat(count = -1) {
return function repeatOperatorFunction(source) {
return new RepeatIterable(source, count);
};
}
exports.repeat = repeat;
//# sourceMappingURL=repeat.js.map