Method While
View SourceWhile<TSource>(Func<bool>, IAsyncEnumerable<TSource>)
Generates an enumerable sequence by repeating a source sequence as long as the given loop condition holds.
Declaration
public static IAsyncEnumerable<TSource> While<TSource>(Func<bool> condition, IAsyncEnumerable<TSource> source)
Parameters
Type | Name | Description |
---|---|---|
Func<bool> | condition | Loop condition. |
IAsyncEnumerable<TSource> | source | Sequence to repeat while the condition evaluates true. |
Returns
Type | Description |
---|---|
IAsyncEnumerable<TSource> | Sequence generated by repeating the given sequence while the condition evaluates to true. |
Type Parameters
Name | Description |
---|---|
TSource | Source sequence element type. |
Remarks
condition
is evaluated lazily, once at the start of each loop of source
.
source
is cached via Memoize<TSource>(IAsyncEnumerable<TSource>), so that it
is only iterated once during the first loop. Successive loops will enumerate the cache instead of source
.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|
While<TSource>(Func<ValueTask<bool>>, IAsyncEnumerable<TSource>)
Generates an enumerable sequence by repeating a source sequence as long as the given loop condition holds.
Declaration
public static IAsyncEnumerable<TSource> While<TSource>(Func<ValueTask<bool>> condition, IAsyncEnumerable<TSource> source)
Parameters
Type | Name | Description |
---|---|---|
Func<ValueTask<bool>> | condition | Loop condition. |
IAsyncEnumerable<TSource> | source | Sequence to repeat while the condition evaluates true. |
Returns
Type | Description |
---|---|
IAsyncEnumerable<TSource> | Sequence generated by repeating the given sequence while the condition evaluates to true. |
Type Parameters
Name | Description |
---|---|
TSource | Source sequence element type. |
Remarks
condition
is evaluated lazily, once at the start of each loop of source
.
source
is cached via Memoize<TSource>(IAsyncEnumerable<TSource>), so that it
is only iterated once during the first loop. Successive loops will enumerate the cache instead of source
.
Exceptions
Type | Condition |
---|---|
ArgumentNullException |
|