Dasync.Collections.IAsyncEnumerableExtensions
Extension methods for IAsyncEnumerable<T> interface
public static Task<TSource> AggregateAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, TSource, TSource> func, CancellationToken cancellationToken = default)
Applies an accumulator function over a sequence.
public static Task<TAccumulate> AggregateAsync<TSource, TAccumulate>(this IAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> func, CancellationToken cancellationToken = default)
Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value.
public static Task<TResult> AggregateAsync<TSource, TAccumulate, TResult>(this IAsyncEnumerable<TSource> source, TAccumulate seed, Func<TAccumulate, TSource, TAccumulate> func, Func<TAccumulate, TResult> resultSelector, CancellationToken cancellationToken = default)
Applies an accumulator function over a sequence. The specified seed value is used as the initial accumulator value, and the specified function is used to select the result value.
public static Task<bool> AllAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, bool> predicate, CancellationToken cancellationToken = default)
Determines whether all elements of a sequence satisfy a condition.
public static Task<bool> AnyAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, bool> predicate, CancellationToken cancellationToken = default)
Determines whether any element of a sequence exists or satisfies a condition.
public static IAsyncEnumerable<TSource> Append<TSource>(this IAsyncEnumerable<TSource> source, TSource element)
Creates a new sequence based on input one plus an extra element at the end.
public static IAsyncEnumerable<List<TSource>> Batch<TSource>(this IAsyncEnumerable<TSource> source, int batchSize)
Splits the input collection into series of batches.
public static IAsyncEnumerable<TStandardCollection> Batch<TSource, TStandardCollection>(this IAsyncEnumerable<TSource> source, int batchSize)
Splits the input collection into series of batches.
public static IAsyncEnumerable<List<TSource>> Batch<TSource>(this IAsyncEnumerable<TSource> source, long maxBatchWeight, Func<TSource, long> weightSelector)
Splits the input collection into series of batches.
public static IAsyncEnumerable<TStandardCollection> Batch<TSource, TStandardCollection>(this IAsyncEnumerable<TSource> source, long maxBatchWeight, Func<TSource, long> weightSelector)
Splits the input collection into series of batches.
public static IAsyncEnumerable<List<TSource>> Batch<TSource>(this IAsyncEnumerable<TSource> source, int maxItemsInBatch, long maxBatchWeight, Func<TSource, long> weightSelector)
Splits the input collection into series of batches.
public static IAsyncEnumerable<TStandardCollection> Batch<TSource, TStandardCollection>(this IAsyncEnumerable<TSource> source, int maxItemsInBatch, long maxBatchWeight, Func<TSource, long> weightSelector)
Splits the input collection into series of batches.
public static IAsyncEnumerable<TBatch> Batch<TSource, TBatch>(this IAsyncEnumerable<TSource> source, int? maxItemsInBatch, long maxBatchWeight, Func<TSource, long> weightSelector, Func<int?, TBatch> createBatch, Action<TBatch, TSource> addItem)
Splits the input collection into series of batches.
Casts the elements of an IAsyncEnumerable to the specified type.
public static IAsyncEnumerable<TSource> Concat<TSource>(this IAsyncEnumerable<TSource> first, IAsyncEnumerable<TSource> second)
Concatenates two sequences.
public static IAsyncEnumerable<TSource> DefaultIfEmpty<TSource>(this IAsyncEnumerable<TSource> source)
Returns the elements of the specified sequence or the specified value in a singleton collection if the sequence is empty.
public static IAsyncEnumerable<TSource> DefaultIfEmpty<TSource>(this IAsyncEnumerable<TSource> source, TSource defaultValue)
Returns the elements of the specified sequence or the specified value in a singleton collection if the sequence is empty.
Returns distinct elements from a sequence by using the default equality comparer to compare values.
public static IAsyncEnumerable<TSource> Distinct<TSource>(this IAsyncEnumerable<TSource> source, IEqualityComparer<TSource> comparer)
Returns distinct elements from a sequence by using a specified IEqualityComparer<T> to compare values.
public static Task<TSource> FirstAsync<TSource>(this IAsyncEnumerable<TSource> source, CancellationToken token = default)
Returns the first element in the IAsyncEnumerable<T>.
public static Task<TSource> FirstAsync<TSource>(this IAsyncEnumerable<TSource> source, string exceptionMessage, CancellationToken token = default)
Returns the first element in the IAsyncEnumerable<T>.
public static Task<TSource> FirstAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, bool> predicate, CancellationToken token = default)
Returns the first element in a sequence that satisfies a specified condition.
public static Task<TSource> FirstAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, bool> predicate, string exceptionMessage, CancellationToken token = default)
Returns the first element in a sequence that satisfies a specified condition.
public static Task<TSource> FirstOrDefaultAsync<TSource>(this IAsyncEnumerable<TSource> source, CancellationToken token = default)
Returns the first element in the IAsyncEnumerable<T>, or a default value if no element is found.
public static Task<TSource> FirstOrDefaultAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, bool> predicate, CancellationToken token = default)
Returns the first element in a sequence that satisfies a specified condition, or a default value if no element is found.
Filters the elements of an IAsyncEnumerable based on a specified type.
public static IAsyncEnumerable<TSource> Prepend<TSource>(this IAsyncEnumerable<TSource> source, TSource element)
Creates a new sequence based on input one plus an extra element in the beginning.
public static IAsyncEnumerable<TResult> Select<TSource, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, TResult> selector)
Projects each element of a sequence into a new form.
public static IAsyncEnumerable<TResult> Select<TSource, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, long, TResult> selector)
Projects each element of a sequence into a new form.
public static IAsyncEnumerable<TResult> SelectMany<TSource, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, IAsyncEnumerable<TResult>> selector)
Projects each element of a sequence to an IAsyncEnumerable<T> and flattens the resulting sequences into one sequence.
public static IAsyncEnumerable<TResult> SelectMany<TSource, TItem, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, IAsyncEnumerable<TItem>> collectionSelector, Func<TSource, TItem, TResult> resultSelector)
Projects each element of a sequence to an IAsyncEnumerable<T> and flattens the resulting sequences into one sequence.
public static IAsyncEnumerable<TResult> SelectMany<TSource, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, IEnumerable<TResult>> selector)
Projects each element of a sequence to an IAsyncEnumerable<T> and flattens the resulting sequences into one sequence.
public static IAsyncEnumerable<TResult> SelectMany<TSource, TItem, TResult>(this IAsyncEnumerable<TSource> source, Func<TSource, IEnumerable<TItem>> collectionSelector, Func<TSource, TItem, TResult> resultSelector)
Projects each element of a sequence to an IAsyncEnumerable<T> and flattens the resulting sequences into one sequence.
public static Task<TSource> SingleAsync<TSource>(this IAsyncEnumerable<TSource> source, CancellationToken token = default)
Returns the only element of a sequence, and throws an exception if there is not exactly one element in the sequence.
public static Task<TSource> SingleAsync<TSource>(this IAsyncEnumerable<TSource> source, string noneExceptionMessage, string manyExceptionMessage, CancellationToken token = default)
Returns the only element of a sequence, and throws an exception if there is not exactly one element in the sequence.
public static Task<TSource> SingleAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, bool> predicate, CancellationToken token = default)
Returns the only element of a sequence, and throws an exception if there is not exactly one element in the sequence that matches the criteria.
public static Task<TSource> SingleAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, bool> predicate, string noneExceptionMessage, string manyExceptionMessage, CancellationToken token = default)
Returns the only element of a sequence, and throws an exception if there is not exactly one element in the sequence that matches the criteria.
public static Task<TSource> SingleOrDefaultAsync<TSource>(this IAsyncEnumerable<TSource> source, CancellationToken token = default)
Returns the only element of a sequence, and returns a default value if there is not exactly one element in the sequence.
public static Task<TSource> SingleOrDefaultAsync<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, bool> predicate, CancellationToken token = default)
Returns the only element of a sequence, and returns a default value if there is not exactly one element in the sequence that matches the criteria.
public static IAsyncEnumerable<TSource> Skip<TSource>(this IAsyncEnumerable<TSource> source, int count)
An IAsyncEnumerable<T> to return elements from.
public static IAsyncEnumerable<TSource> SkipWhile<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, bool> predicate)
Bypasses elements in a sequence as long as a specified condition is true and then returns the remaining elements.
public static IAsyncEnumerable<TSource> Take<TSource>(this IAsyncEnumerable<TSource> source, int count)
Returns a specified number of contiguous elements from the start of a sequence.
public static IAsyncEnumerable<TSource> TakeWhile<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, bool> predicate)
Returns elements from a sequence as long as a specified condition is true.
public static Task<T[]> ToArrayAsync<T>(this IAsyncEnumerable<T> source, CancellationToken cancellationToken = default)
Creates an array of elements asynchronously from the enumerable source
public static Task<Dictionary<TKey, TSource>> ToDictionaryAsync<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, CancellationToken cancellationToken = default)
Creates a Dictionary<T, U> from an IAsyncEnumerable<T> according to a specified key selector function, a comparer, and an element selector function.
public static Task<Dictionary<TKey, TSource>> ToDictionaryAsync<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
Creates a Dictionary<T, U> from an IAsyncEnumerable<T> according to a specified key selector function, a comparer, and an element selector function.
public static Task<Dictionary<TKey, TElement>> ToDictionaryAsync<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, CancellationToken cancellationToken = default)
Creates a Dictionary<T, U> from an IAsyncEnumerable<T> according to a specified key selector function, a comparer, and an element selector function.
public static Task<Dictionary<TKey, TElement>> ToDictionaryAsync<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
Creates a Dictionary<T, U> from an IAsyncEnumerable<T> according to a specified key selector function, a comparer, and an element selector function.
public static Task<List<T>> ToListAsync<T>(this IAsyncEnumerable<T> source, CancellationToken cancellationToken = default)
Creates a list of elements asynchronously from the enumerable source
public static Task<ILookup<TKey, TSource>> ToLookupAsync<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, CancellationToken cancellationToken = default)
Creates a ILookup<T, U> from an IAsyncEnumerable<T> according to a specified key selector function.
public static Task<ILookup<TKey, TSource>> ToLookupAsync<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
Creates a ILookup<T, U> from an IAsyncEnumerable<T> according to a specified key selector function and key comparer.
public static Task<ILookup<TKey, TElement>> ToLookupAsync<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, CancellationToken cancellationToken = default)
Creates a ILookup<T, U> from an IAsyncEnumerable<T> according to a specified key selector function and an element selector function.
public static Task<ILookup<TKey, TElement>> ToLookupAsync<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken = default)
Creates a ILookup<T, U> from an IAsyncEnumerable<T> according to a specified key selector function, a comparer and an element selector function.
public static IAsyncEnumerable<T> UnionAll<T>(this IAsyncEnumerable<T> first, IAsyncEnumerable<T> second)
Produces the set union of two sequences, which includes duplicate elements.
Produces the set union of multiple sequences, which includes duplicate elements.
public static IAsyncEnumerable<TSource> Where<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, bool> predicate)
Filters a sequence of values based on a predicate.
public static IAsyncEnumerable<TSource> Where<TSource>(this IAsyncEnumerable<TSource> source, Func<TSource, long, bool> predicate)
Projects each element of a sequence into a new form.