Class IAsyncEnumerableLegacyExtensions
- Namespace
- Wolfgang.Extensions.IAsyncEnumerable
- Assembly
- Wolfgang.Extensions.IAsyncEnumerable.Legacy.dll
Terminal operator extension methods for IAsyncEnumerable{T}, for consumers on net462 / netstandard2.0 where System.Linq.AsyncEnumerable is not available.
public static class IAsyncEnumerableLegacyExtensions
- Inheritance
-
IAsyncEnumerableLegacyExtensions
- Inherited Members
Methods
AnyAsync<T>(IAsyncEnumerable<T>, Func<T, bool>, CancellationToken)
Asynchronously determines whether any element of a sequence satisfies a condition.
public static ValueTask<bool> AnyAsync<T>(this IAsyncEnumerable<T> source, Func<T, bool> predicate, CancellationToken token = default)
Parameters
sourceIAsyncEnumerable<T>The IAsyncEnumerable{T} whose elements to apply the predicate to.
predicateFunc<T, bool>A function to test each element for a condition.
tokenCancellationTokenA cancellation token to cancel the operation.
Returns
- ValueTask<bool>
true if any elements in the source sequence pass the test in the specified predicate; otherwise, false.
Type Parameters
TThe type of elements in the IAsyncEnumerable{T}.
Exceptions
- ArgumentNullException
Thrown when
sourceorpredicateis null.- OperationCanceledException
Thrown when
tokenis canceled before or during enumeration. Delivered through the returned ValueTask<TResult>.
AnyAsync<T>(IAsyncEnumerable<T>, CancellationToken)
Asynchronously determines whether a sequence contains any elements.
public static ValueTask<bool> AnyAsync<T>(this IAsyncEnumerable<T> source, CancellationToken token = default)
Parameters
sourceIAsyncEnumerable<T>The IAsyncEnumerable{T} to check.
tokenCancellationTokenA cancellation token to cancel the operation.
Returns
Type Parameters
TThe type of elements in the IAsyncEnumerable{T}.
Exceptions
- ArgumentNullException
Thrown when
sourceis null.- OperationCanceledException
Thrown when
tokenis canceled before or during enumeration. Delivered through the returned ValueTask<TResult>.
CountAsync<T>(IAsyncEnumerable<T>, CancellationToken)
Asynchronously counts the elements in a sequence.
public static ValueTask<int> CountAsync<T>(this IAsyncEnumerable<T> source, CancellationToken token = default)
Parameters
sourceIAsyncEnumerable<T>The IAsyncEnumerable{T} to count.
tokenCancellationTokenA cancellation token to cancel the operation.
Returns
Type Parameters
TThe type of elements in the IAsyncEnumerable{T}.
Exceptions
- ArgumentNullException
Thrown when
sourceis null.- OperationCanceledException
Thrown when
tokenis canceled before or during enumeration. Delivered through the returned ValueTask<TResult>.
FirstAsync<T>(IAsyncEnumerable<T>, CancellationToken)
Asynchronously returns the first element of a sequence.
public static ValueTask<T> FirstAsync<T>(this IAsyncEnumerable<T> source, CancellationToken token = default)
Parameters
sourceIAsyncEnumerable<T>The IAsyncEnumerable{T} to return the first element of.
tokenCancellationTokenA cancellation token to cancel the operation.
Returns
- ValueTask<T>
The first element in the source sequence.
Type Parameters
TThe type of elements in the IAsyncEnumerable{T}.
Exceptions
- ArgumentNullException
Thrown when
sourceis null.- InvalidOperationException
Thrown when the source sequence contains no elements.
- OperationCanceledException
Thrown when
tokenis canceled before or during enumeration. Delivered through the returned ValueTask<TResult>.
FirstOrDefaultAsync<T>(IAsyncEnumerable<T>, CancellationToken)
Asynchronously returns the first element of a sequence, or a default value if the sequence contains no elements.
public static ValueTask<T?> FirstOrDefaultAsync<T>(this IAsyncEnumerable<T> source, CancellationToken token = default)
Parameters
sourceIAsyncEnumerable<T>The IAsyncEnumerable{T} to return the first element of.
tokenCancellationTokenA cancellation token to cancel the operation.
Returns
- ValueTask<T>
The first element in the source sequence, or the default value for
Tif the sequence contains no elements.
Type Parameters
TThe type of elements in the IAsyncEnumerable{T}.
Exceptions
- ArgumentNullException
Thrown when
sourceis null.- OperationCanceledException
Thrown when
tokenis canceled before or during enumeration. Delivered through the returned ValueTask<TResult>.
ToListAsync<T>(IAsyncEnumerable<T>, CancellationToken)
Asynchronously creates a List{T} from an IAsyncEnumerable{T}.
public static ValueTask<List<T>> ToListAsync<T>(this IAsyncEnumerable<T> source, CancellationToken token = default)
Parameters
sourceIAsyncEnumerable<T>The IAsyncEnumerable{T} to create a List{T} from.
tokenCancellationTokenA cancellation token to cancel the operation.
Returns
Type Parameters
TThe type of elements in the IAsyncEnumerable{T}.
Exceptions
- ArgumentNullException
Thrown when
sourceis null.- OperationCanceledException
Thrown when
tokenis canceled before or during enumeration. Delivered through the returned ValueTask<TResult>.