1 | import { IterableX } from './iterablex';
|
2 | class WhileIterable extends IterableX {
|
3 | constructor(condition, source) {
|
4 | super();
|
5 | this._condition = condition;
|
6 | this._source = source;
|
7 | }
|
8 | *[Symbol.iterator]() {
|
9 | while (this._condition()) {
|
10 | yield* this._source;
|
11 | }
|
12 | }
|
13 | }
|
14 | /**
|
15 | * Repeats the given source as long as the specified conditions holds, where
|
16 | * the condition is evaluated before each repeated source is iterated.
|
17 | *
|
18 | * @export
|
19 | * @template TSource
|
20 | * @param {Iterable<TSource>} source Source to repeat as long as the condition function evaluates to true.
|
21 | * @param {((signal?: AbortSignal) => boolean)} condition Condition that will be evaluated before the source sequence is iterated.
|
22 | * @returns {IterableX<TSource>} An iterable which is repeated while the condition returns true.
|
23 | */
|
24 | export function whileDo(source, condition) {
|
25 | return new WhileIterable(condition, source);
|
26 | }
|
27 |
|
28 | //# sourceMappingURL=whiledo.mjs.map
|