Method Choose
View SourceChoose<T, TResult>(IAsyncEnumerable<T>, Func<T, (bool, TResult)>)
Applies a function to each element of the source sequence and returns a new sequence of result elements for source elements where the function returns a couple (2-tuple) having a true as its first element and result as the second.
Declaration
public static IAsyncEnumerable<TResult> Choose<T, TResult>(this IAsyncEnumerable<T> source, Func<T, (bool, TResult)> chooser)
Parameters
Type | Name | Description |
---|---|---|
IAsyncEnumerable<T> | source | The source sequence. |
Func<T, (bool, TResult)> | chooser | The function that is applied to each source element. |
Returns
Type | Description |
---|---|
IAsyncEnumerable<TResult> | A sequence |
Type Parameters
Name | Description |
---|---|
T | The type of the elements in |
TResult | The type of the elements in the returned sequence. |
Remarks
This method uses deferred execution semantics and streams its results.
Examples
var str = "O,l,2,3,4,S,6,7,B,9";
var xs = str.Split(',').Choose(s => (int.TryParse(s, out var n), n));
The <code>xs</code> variable will be a sequence of the integers 2, 3, 4,
6, 7 and 9.
View Source
Choose<T, TResult>(IAsyncEnumerable<T>, Func<T, ValueTask<(bool, TResult)>>)
Applies a function to each element of the source sequence and returns a new sequence of result elements for source elements where the function returns a couple (2-tuple) having a true as its first element and result as the second.
Declaration
public static IAsyncEnumerable<TResult> Choose<T, TResult>(this IAsyncEnumerable<T> source, Func<T, ValueTask<(bool, TResult)>> chooser)
Parameters
Type | Name | Description |
---|---|---|
IAsyncEnumerable<T> | source | The source sequence. |
Func<T, ValueTask<(bool, TResult)>> | chooser | The function that is applied to each source element. |
Returns
Type | Description |
---|---|
IAsyncEnumerable<TResult> | A sequence |
Type Parameters
Name | Description |
---|---|
T | The type of the elements in |
TResult | The type of the elements in the returned sequence. |
Remarks
This method uses deferred execution semantics and streams its results.
Examples
var str = "O,l,2,3,4,S,6,7,B,9";
var xs = str.Split(',').Choose(s => (int.TryParse(s, out var n), n));
The <code>xs</code> variable will be a sequence of the integers 2, 3, 4,
6, 7 and 9.
View Source
Choose<T, TResult>(IAsyncEnumerable<T>, Func<T, CancellationToken, ValueTask<(bool, TResult)>>)
Applies a function to each element of the source sequence and returns a new sequence of result elements for source elements where the function returns a couple (2-tuple) having a true as its first element and result as the second.
Declaration
public static IAsyncEnumerable<TResult> Choose<T, TResult>(this IAsyncEnumerable<T> source, Func<T, CancellationToken, ValueTask<(bool, TResult)>> chooser)
Parameters
Type | Name | Description |
---|---|---|
IAsyncEnumerable<T> | source | The source sequence. |
Func<T, CancellationToken, ValueTask<(bool, TResult)>> | chooser | The function that is applied to each source element. |
Returns
Type | Description |
---|---|
IAsyncEnumerable<TResult> | A sequence |
Type Parameters
Name | Description |
---|---|
T | The type of the elements in |
TResult | The type of the elements in the returned sequence. |
Remarks
This method uses deferred execution semantics and streams its results.
Examples
var str = "O,l,2,3,4,S,6,7,B,9";
var xs = str.Split(',').Choose(s => (int.TryParse(s, out var n), n));
The <code>xs</code> variable will be a sequence of the integers 2, 3, 4,
6, 7 and 9.