Class XAsyncEnumerable
- Namespace
- Prefrontal.Common.Extensions.Async
- Assembly
- Prefrontal.Core.dll
public static class XAsyncEnumerable
- Inheritance
-
XAsyncEnumerable
- Inherited Members
Methods
Append<T>(IAsyncEnumerable<T>, params IEnumerable<T>)
Appends a value to the end of the sequence.
public static IAsyncEnumerable<T> Append<T>(this IAsyncEnumerable<T> source, params IEnumerable<T> itemsToAppend)
Parameters
sourceIAsyncEnumerable<T>A sequence of values.
itemsToAppendIEnumerable<T>
Returns
- IAsyncEnumerable<T>
A new sequence that ends with
element.
Type Parameters
T
Exceptions
- ArgumentNullException
sourceis null.
Cast<TSource, TTarget>(IAsyncEnumerable<TSource>)
public static IAsyncEnumerable<TTarget> Cast<TSource, TTarget>(this IAsyncEnumerable<TSource> source)
Parameters
sourceIAsyncEnumerable<TSource>
Returns
- IAsyncEnumerable<TTarget>
Type Parameters
TSourceTTarget
Concat<T>(IAsyncEnumerable<T>, IAsyncEnumerable<T>)
Concatenates two sequences.
public static IAsyncEnumerable<T> Concat<T>(this IAsyncEnumerable<T> first, IAsyncEnumerable<T> second)
Parameters
firstIAsyncEnumerable<T>The first sequence to concatenate.
secondIAsyncEnumerable<T>The sequence to concatenate to the first sequence.
Returns
- IAsyncEnumerable<T>
An IEnumerable<T> that contains the concatenated elements of the two input sequences.
Type Parameters
T
Exceptions
- ArgumentNullException
firstorsecondis null.
Concat<T>(IAsyncEnumerable<T>, IEnumerable<T>)
Concatenates two sequences.
public static IAsyncEnumerable<T> Concat<T>(this IAsyncEnumerable<T> first, IEnumerable<T> second)
Parameters
firstIAsyncEnumerable<T>The first sequence to concatenate.
secondIEnumerable<T>The sequence to concatenate to the first sequence.
Returns
- IAsyncEnumerable<T>
An IEnumerable<T> that contains the concatenated elements of the two input sequences.
Type Parameters
T
Exceptions
- ArgumentNullException
firstorsecondis null.
Concat<T>(IEnumerable<T>, IAsyncEnumerable<T>)
Concatenates two sequences.
public static IAsyncEnumerable<T> Concat<T>(this IEnumerable<T> first, IAsyncEnumerable<T> second)
Parameters
firstIEnumerable<T>The first sequence to concatenate.
secondIAsyncEnumerable<T>The sequence to concatenate to the first sequence.
Returns
- IAsyncEnumerable<T>
An IEnumerable<T> that contains the concatenated elements of the two input sequences.
Type Parameters
T
Exceptions
- ArgumentNullException
firstorsecondis null.
FirstAsync<T>(IAsyncEnumerable<T>)
Returns the first element of a sequence.
public static Task<T> FirstAsync<T>(this IAsyncEnumerable<T> source)
Parameters
sourceIAsyncEnumerable<T>The IEnumerable<T> to return the first element of.
Returns
- Task<T>
The first element in the specified sequence.
Type Parameters
T
Exceptions
- ArgumentNullException
sourceis null.- InvalidOperationException
The source sequence is empty.
FirstAsync<T>(IAsyncEnumerable<T>, Func<T, bool>)
Returns the first element in a sequence that satisfies a specified condition.
public static Task<T> FirstAsync<T>(this IAsyncEnumerable<T> source, Func<T, bool> predicate)
Parameters
sourceIAsyncEnumerable<T>An IEnumerable<T> to return an element from.
predicateFunc<T, bool>A function to test each element for a condition.
Returns
- Task<T>
The first element in the sequence that passes the test in the specified predicate function.
Type Parameters
T
Exceptions
- ArgumentNullException
sourceorpredicateis null.- InvalidOperationException
No element satisfies the condition in
predicate.-or-
The source sequence is empty.
FirstOrDefaultAsync<T>(IAsyncEnumerable<T>, Func<T, bool>, T?)
Returns the first element of the sequence that satisfies a condition, or a specified default value if no such element is found.
public static Task<T?> FirstOrDefaultAsync<T>(this IAsyncEnumerable<T> source, Func<T, bool> predicate, T? defaultValue = default)
Parameters
sourceIAsyncEnumerable<T>An IEnumerable<T> to return an element from.
predicateFunc<T, bool>A function to test each element for a condition.
defaultValueTThe default value to return if the sequence is empty.
Returns
- Task<T>
defaultValueifsourceis empty or if no element passes the test specified bypredicate; otherwise, the first element insourcethat passes the test specified bypredicate.
Type Parameters
T
Exceptions
- ArgumentNullException
sourceorpredicateis null.
FirstOrDefaultAsync<T>(IAsyncEnumerable<T>, T?)
Returns the first element of a sequence, or a specified default value if the sequence contains no elements.
public static Task<T?> FirstOrDefaultAsync<T>(this IAsyncEnumerable<T> source, T? defaultValue = default)
Parameters
sourceIAsyncEnumerable<T>The IEnumerable<T> to return the first element of.
defaultValueTThe default value to return if the sequence is empty.
Returns
- Task<T>
defaultValueifsourceis empty; otherwise, the first element insource.
Type Parameters
T
Exceptions
- ArgumentNullException
sourceis null.
LastAsync<T>(IAsyncEnumerable<T>)
Returns the last element of a sequence.
public static Task<T> LastAsync<T>(this IAsyncEnumerable<T> source)
Parameters
sourceIAsyncEnumerable<T>An IEnumerable<T> to return the last element of.
Returns
- Task<T>
The value at the last position in the source sequence.
Type Parameters
T
Exceptions
- ArgumentNullException
sourceis null.- InvalidOperationException
The source sequence is empty.
LastAsync<T>(IAsyncEnumerable<T>, Func<T, bool>)
Returns the last element of a sequence that satisfies a specified condition.
public static Task<T> LastAsync<T>(this IAsyncEnumerable<T> source, Func<T, bool> predicate)
Parameters
sourceIAsyncEnumerable<T>An IEnumerable<T> to return an element from.
predicateFunc<T, bool>A function to test each element for a condition.
Returns
- Task<T>
The last element in the sequence that passes the test in the specified predicate function.
Type Parameters
T
Exceptions
- ArgumentNullException
sourceorpredicateis null.- InvalidOperationException
No element satisfies the condition in
predicate.-or-
The source sequence is empty.
LastOrDefaultAsync<T>(IAsyncEnumerable<T>, Func<T, bool>, T?)
Returns the last element of a sequence that satisfies a condition, or a specified default value if no such element is found.
public static Task<T?> LastOrDefaultAsync<T>(this IAsyncEnumerable<T> source, Func<T, bool> predicate, T? defaultValue = default)
Parameters
sourceIAsyncEnumerable<T>An IEnumerable<T> to return an element from.
predicateFunc<T, bool>A function to test each element for a condition.
defaultValueTThe default value to return if the sequence is empty.
Returns
- Task<T>
defaultValueif the sequence is empty or if no elements pass the test in the predicate function; otherwise, the last element that passes the test in the predicate function.
Type Parameters
T
Exceptions
- ArgumentNullException
sourceorpredicateis null.
LastOrDefaultAsync<T>(IAsyncEnumerable<T>, T?)
Returns the last element of a sequence, or a specified default value if the sequence contains no elements.
public static Task<T?> LastOrDefaultAsync<T>(this IAsyncEnumerable<T> source, T? defaultValue = default)
Parameters
sourceIAsyncEnumerable<T>An IEnumerable<T> to return the last element of.
defaultValueTThe default value to return if the sequence is empty.
Returns
- Task<T>
defaultValueif the source sequence is empty; otherwise, the last element in the IEnumerable<T>.
Type Parameters
T
Exceptions
- ArgumentNullException
sourceis null.
Prepend<T>(IAsyncEnumerable<T>, params IEnumerable<T>)
Adds a value to the beginning of the sequence.
public static IAsyncEnumerable<T> Prepend<T>(this IAsyncEnumerable<T> source, params IEnumerable<T> itemsToPrepend)
Parameters
sourceIAsyncEnumerable<T>A sequence of values.
itemsToPrependIEnumerable<T>
Returns
- IAsyncEnumerable<T>
A new sequence that begins with
element.
Type Parameters
T
Exceptions
- ArgumentNullException
sourceis null.
Select<TSource, TResult>(IAsyncEnumerable<TSource>, Func<TSource, TResult>)
Projects each element of a sequence into a new form.
public static IAsyncEnumerable<TResult> Select<TSource, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, TResult> selector)
Parameters
sourceIAsyncEnumerable<TSource>A sequence of values to invoke a transform function on.
selectorFunc<TSource, TResult>A transform function to apply to each element.
Returns
- IAsyncEnumerable<TResult>
An IEnumerable<T> whose elements are the result of invoking the transform function on each element of
source.
Type Parameters
TSourceThe type of the elements of
source.TResultThe type of the value returned by
selector.
Exceptions
- ArgumentNullException
sourceorselectoris null.
ToListAsync<T>(IAsyncEnumerable<T>)
public static Task<List<T>> ToListAsync<T>(this IAsyncEnumerable<T> source)
Parameters
sourceIAsyncEnumerable<T>
Returns
Type Parameters
T
ToTask<T>(IAsyncEnumerable<T>)
public static Task ToTask<T>(this IAsyncEnumerable<T> source)
Parameters
sourceIAsyncEnumerable<T>
Returns
Type Parameters
T
Where<T>(IAsyncEnumerable<T>, Func<T, bool>)
Filters a sequence of values based on a predicate.
public static IAsyncEnumerable<T> Where<T>(this IAsyncEnumerable<T> source, Func<T, bool> predicate)
Parameters
sourceIAsyncEnumerable<T>An IEnumerable<T> to filter.
predicateFunc<T, bool>A function to test each element for a condition.
Returns
- IAsyncEnumerable<T>
An IEnumerable<T> that contains elements from the input sequence that satisfy the condition.
Type Parameters
T
Exceptions
- ArgumentNullException
sourceorpredicateis null.