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

source IAsyncEnumerable<T>

The IAsyncEnumerable{T} whose elements to apply the predicate to.

predicate Func<T, bool>

A function to test each element for a condition.

token CancellationToken

A 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

T

The type of elements in the IAsyncEnumerable{T}.

Exceptions

ArgumentNullException

Thrown when source or predicate is null.

OperationCanceledException

Thrown when token is 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

source IAsyncEnumerable<T>

The IAsyncEnumerable{T} to check.

token CancellationToken

A cancellation token to cancel the operation.

Returns

ValueTask<bool>

true if the source sequence contains any elements; otherwise, false.

Type Parameters

T

The type of elements in the IAsyncEnumerable{T}.

Exceptions

ArgumentNullException

Thrown when source is null.

OperationCanceledException

Thrown when token is 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

source IAsyncEnumerable<T>

The IAsyncEnumerable{T} to count.

token CancellationToken

A cancellation token to cancel the operation.

Returns

ValueTask<int>

The number of elements in the source sequence.

Type Parameters

T

The type of elements in the IAsyncEnumerable{T}.

Exceptions

ArgumentNullException

Thrown when source is null.

OperationCanceledException

Thrown when token is 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

source IAsyncEnumerable<T>

The IAsyncEnumerable{T} to return the first element of.

token CancellationToken

A cancellation token to cancel the operation.

Returns

ValueTask<T>

The first element in the source sequence.

Type Parameters

T

The type of elements in the IAsyncEnumerable{T}.

Exceptions

ArgumentNullException

Thrown when source is null.

InvalidOperationException

Thrown when the source sequence contains no elements.

OperationCanceledException

Thrown when token is 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

source IAsyncEnumerable<T>

The IAsyncEnumerable{T} to return the first element of.

token CancellationToken

A cancellation token to cancel the operation.

Returns

ValueTask<T>

The first element in the source sequence, or the default value for T if the sequence contains no elements.

Type Parameters

T

The type of elements in the IAsyncEnumerable{T}.

Exceptions

ArgumentNullException

Thrown when source is null.

OperationCanceledException

Thrown when token is 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

source IAsyncEnumerable<T>

The IAsyncEnumerable{T} to create a List{T} from.

token CancellationToken

A cancellation token to cancel the operation.

Returns

ValueTask<List<T>>

A List{T} containing every element of the source sequence, in enumeration order.

Type Parameters

T

The type of elements in the IAsyncEnumerable{T}.

Exceptions

ArgumentNullException

Thrown when source is null.

OperationCanceledException

Thrown when token is canceled before or during enumeration. Delivered through the returned ValueTask<TResult>.