Table of Contents

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

source IAsyncEnumerable<T>

A sequence of values.

itemsToAppend IEnumerable<T>

Returns

IAsyncEnumerable<T>

A new sequence that ends with element.

Type Parameters

T

Exceptions

ArgumentNullException

source is null.

Cast<TSource, TTarget>(IAsyncEnumerable<TSource>)

public static IAsyncEnumerable<TTarget> Cast<TSource, TTarget>(this IAsyncEnumerable<TSource> source)

Parameters

source IAsyncEnumerable<TSource>

Returns

IAsyncEnumerable<TTarget>

Type Parameters

TSource
TTarget

Concat<T>(IAsyncEnumerable<T>, IAsyncEnumerable<T>)

Concatenates two sequences.

public static IAsyncEnumerable<T> Concat<T>(this IAsyncEnumerable<T> first, IAsyncEnumerable<T> second)

Parameters

first IAsyncEnumerable<T>

The first sequence to concatenate.

second IAsyncEnumerable<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

first or second is null.

Concat<T>(IAsyncEnumerable<T>, IEnumerable<T>)

Concatenates two sequences.

public static IAsyncEnumerable<T> Concat<T>(this IAsyncEnumerable<T> first, IEnumerable<T> second)

Parameters

first IAsyncEnumerable<T>

The first sequence to concatenate.

second IEnumerable<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

first or second is null.

Concat<T>(IEnumerable<T>, IAsyncEnumerable<T>)

Concatenates two sequences.

public static IAsyncEnumerable<T> Concat<T>(this IEnumerable<T> first, IAsyncEnumerable<T> second)

Parameters

first IEnumerable<T>

The first sequence to concatenate.

second IAsyncEnumerable<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

first or second is null.

FirstAsync<T>(IAsyncEnumerable<T>)

Returns the first element of a sequence.

public static Task<T> FirstAsync<T>(this IAsyncEnumerable<T> source)

Parameters

source IAsyncEnumerable<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

source is 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

source IAsyncEnumerable<T>

An IEnumerable<T> to return an element from.

predicate Func<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

source or predicate is 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

source IAsyncEnumerable<T>

An IEnumerable<T> to return an element from.

predicate Func<T, bool>

A function to test each element for a condition.

defaultValue T

The default value to return if the sequence is empty.

Returns

Task<T>

defaultValue if source is empty or if no element passes the test specified by predicate; otherwise, the first element in source that passes the test specified by predicate.

Type Parameters

T

Exceptions

ArgumentNullException

source or predicate is 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

source IAsyncEnumerable<T>

The IEnumerable<T> to return the first element of.

defaultValue T

The default value to return if the sequence is empty.

Returns

Task<T>

defaultValue if source is empty; otherwise, the first element in source.

Type Parameters

T

Exceptions

ArgumentNullException

source is null.

LastAsync<T>(IAsyncEnumerable<T>)

Returns the last element of a sequence.

public static Task<T> LastAsync<T>(this IAsyncEnumerable<T> source)

Parameters

source IAsyncEnumerable<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

source is 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

source IAsyncEnumerable<T>

An IEnumerable<T> to return an element from.

predicate Func<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

source or predicate is 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

source IAsyncEnumerable<T>

An IEnumerable<T> to return an element from.

predicate Func<T, bool>

A function to test each element for a condition.

defaultValue T

The default value to return if the sequence is empty.

Returns

Task<T>

defaultValue if 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

source or predicate is 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

source IAsyncEnumerable<T>

An IEnumerable<T> to return the last element of.

defaultValue T

The default value to return if the sequence is empty.

Returns

Task<T>

defaultValue if the source sequence is empty; otherwise, the last element in the IEnumerable<T>.

Type Parameters

T

Exceptions

ArgumentNullException

source is 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

source IAsyncEnumerable<T>

A sequence of values.

itemsToPrepend IEnumerable<T>

Returns

IAsyncEnumerable<T>

A new sequence that begins with element.

Type Parameters

T

Exceptions

ArgumentNullException

source is 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

source IAsyncEnumerable<TSource>

A sequence of values to invoke a transform function on.

selector Func<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

TSource

The type of the elements of source.

TResult

The type of the value returned by selector.

Exceptions

ArgumentNullException

source or selector is null.

ToListAsync<T>(IAsyncEnumerable<T>)

public static Task<List<T>> ToListAsync<T>(this IAsyncEnumerable<T> source)

Parameters

source IAsyncEnumerable<T>

Returns

Task<List<T>>

Type Parameters

T

ToTask<T>(IAsyncEnumerable<T>)

public static Task ToTask<T>(this IAsyncEnumerable<T> source)

Parameters

source IAsyncEnumerable<T>

Returns

Task

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

source IAsyncEnumerable<T>

An IEnumerable<T> to filter.

predicate Func<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

source or predicate is null.