// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT License. // See the LICENSE file in the project root for more information. using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; namespace System.Linq { partial class AsyncEnumerable { #if SUPPORT_FLAT_ASYNC_API public static ValueTask SingleAsync(this IAsyncEnumerable source, Func> predicate, CancellationToken cancellationToken = default) => SingleAwaitAsyncCore(source, predicate, cancellationToken); public static ValueTask SingleOrDefaultAsync(this IAsyncEnumerable source, Func> predicate, CancellationToken cancellationToken = default) => SingleOrDefaultAwaitAsyncCore(source, predicate, cancellationToken); public static IAsyncEnumerable SkipWhile(this IAsyncEnumerable source, Func> predicate) => SkipWhileAwaitCore(source, predicate); public static IAsyncEnumerable SkipWhile(this IAsyncEnumerable source, Func> predicate) => SkipWhileAwaitCore(source, predicate); public static ValueTask SumAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitAsyncCore(source, selector, cancellationToken); public static ValueTask SumAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitAsyncCore(source, selector, cancellationToken); public static ValueTask SumAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitAsyncCore(source, selector, cancellationToken); public static ValueTask SumAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitAsyncCore(source, selector, cancellationToken); public static ValueTask SumAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitAsyncCore(source, selector, cancellationToken); public static ValueTask SumAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitAsyncCore(source, selector, cancellationToken); public static ValueTask SumAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitAsyncCore(source, selector, cancellationToken); public static ValueTask SumAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitAsyncCore(source, selector, cancellationToken); public static ValueTask SumAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitAsyncCore(source, selector, cancellationToken); public static ValueTask SumAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitAsyncCore(source, selector, cancellationToken); public static IAsyncEnumerable TakeWhile(this IAsyncEnumerable source, Func> predicate) => TakeWhileAwaitCore(source, predicate); public static IAsyncEnumerable TakeWhile(this IAsyncEnumerable source, Func> predicate) => TakeWhileAwaitCore(source, predicate); public static ValueTask> ToDictionaryAsync(this IAsyncEnumerable source, Func> keySelector, CancellationToken cancellationToken = default) where TKey : notnull => ToDictionaryAwaitAsyncCore(source, keySelector, cancellationToken); public static ValueTask> ToDictionaryAsync(this IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) where TKey : notnull => ToDictionaryAwaitAsyncCore(source, keySelector, comparer, cancellationToken); public static ValueTask> ToDictionaryAsync(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, CancellationToken cancellationToken = default) where TKey : notnull => ToDictionaryAwaitAsyncCore(source, keySelector, elementSelector, cancellationToken); public static ValueTask> ToDictionaryAsync(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) where TKey : notnull => ToDictionaryAwaitAsyncCore(source, keySelector, elementSelector, comparer, cancellationToken); public static ValueTask> ToLookupAsync(this IAsyncEnumerable source, Func> keySelector, CancellationToken cancellationToken = default) => ToLookupAwaitAsyncCore(source, keySelector, cancellationToken); public static ValueTask> ToLookupAsync(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, CancellationToken cancellationToken = default) => ToLookupAwaitAsyncCore(source, keySelector, elementSelector, cancellationToken); public static ValueTask> ToLookupAsync(this IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) => ToLookupAwaitAsyncCore(source, keySelector, comparer, cancellationToken); public static ValueTask> ToLookupAsync(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) => ToLookupAwaitAsyncCore(source, keySelector, elementSelector, comparer, cancellationToken); public static IAsyncEnumerable Where(this IAsyncEnumerable source, Func> predicate) => WhereAwaitCore(source, predicate); public static IAsyncEnumerable Where(this IAsyncEnumerable source, Func> predicate) => WhereAwaitCore(source, predicate); public static IAsyncEnumerable Zip(this IAsyncEnumerable first, IAsyncEnumerable second, Func> selector) => ZipAwaitCore(first, second, selector); #if !NO_DEEP_CANCELLATION public static ValueTask SingleAsync(this IAsyncEnumerable source, Func> predicate, CancellationToken cancellationToken = default) => SingleAwaitWithCancellationAsyncCore(source, predicate, cancellationToken); public static ValueTask SingleOrDefaultAsync(this IAsyncEnumerable source, Func> predicate, CancellationToken cancellationToken = default) => SingleOrDefaultAwaitWithCancellationAsyncCore(source, predicate, cancellationToken); public static IAsyncEnumerable SkipWhile(this IAsyncEnumerable source, Func> predicate) => SkipWhileAwaitWithCancellationCore(source, predicate); public static IAsyncEnumerable SkipWhile(this IAsyncEnumerable source, Func> predicate) => SkipWhileAwaitWithCancellationCore(source, predicate); public static ValueTask SumAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitWithCancellationAsyncCore(source, selector, cancellationToken); public static ValueTask SumAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitWithCancellationAsyncCore(source, selector, cancellationToken); public static ValueTask SumAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitWithCancellationAsyncCore(source, selector, cancellationToken); public static ValueTask SumAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitWithCancellationAsyncCore(source, selector, cancellationToken); public static ValueTask SumAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitWithCancellationAsyncCore(source, selector, cancellationToken); public static ValueTask SumAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitWithCancellationAsyncCore(source, selector, cancellationToken); public static ValueTask SumAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitWithCancellationAsyncCore(source, selector, cancellationToken); public static ValueTask SumAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitWithCancellationAsyncCore(source, selector, cancellationToken); public static ValueTask SumAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitWithCancellationAsyncCore(source, selector, cancellationToken); public static ValueTask SumAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitWithCancellationAsyncCore(source, selector, cancellationToken); public static IAsyncEnumerable TakeWhile(this IAsyncEnumerable source, Func> predicate) => TakeWhileAwaitWithCancellationCore(source, predicate); public static IAsyncEnumerable TakeWhile(this IAsyncEnumerable source, Func> predicate) => TakeWhileAwaitWithCancellationCore(source, predicate); public static ValueTask> ToDictionaryAsync(this IAsyncEnumerable source, Func> keySelector, CancellationToken cancellationToken = default) where TKey : notnull => ToDictionaryAwaitWithCancellationAsyncCore(source, keySelector, cancellationToken); public static ValueTask> ToDictionaryAsync(this IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) where TKey : notnull => ToDictionaryAwaitWithCancellationAsyncCore(source, keySelector, comparer, cancellationToken); public static ValueTask> ToDictionaryAsync(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, CancellationToken cancellationToken = default) where TKey : notnull => ToDictionaryAwaitWithCancellationAsyncCore(source, keySelector, elementSelector, cancellationToken); public static ValueTask> ToDictionaryAsync(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) where TKey : notnull => ToDictionaryAwaitWithCancellationAsyncCore(source, keySelector, elementSelector, comparer, cancellationToken); public static ValueTask> ToLookupAsync(this IAsyncEnumerable source, Func> keySelector, CancellationToken cancellationToken = default) => ToLookupAwaitWithCancellationAsyncCore(source, keySelector, cancellationToken); public static ValueTask> ToLookupAsync(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, CancellationToken cancellationToken = default) => ToLookupAwaitWithCancellationAsyncCore(source, keySelector, elementSelector, cancellationToken); public static ValueTask> ToLookupAsync(this IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) => ToLookupAwaitWithCancellationAsyncCore(source, keySelector, comparer, cancellationToken); public static ValueTask> ToLookupAsync(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) => ToLookupAwaitWithCancellationAsyncCore(source, keySelector, elementSelector, comparer, cancellationToken); public static IAsyncEnumerable Where(this IAsyncEnumerable source, Func> predicate) => WhereAwaitWithCancellationCore(source, predicate); public static IAsyncEnumerable Where(this IAsyncEnumerable source, Func> predicate) => WhereAwaitWithCancellationCore(source, predicate); public static IAsyncEnumerable Zip(this IAsyncEnumerable first, IAsyncEnumerable second, Func> selector) => ZipAwaitWithCancellationCore(first, second, selector); #endif #else /// /// Returns the only element of an async-enumerable sequence that satisfies the condition in the asynchronous predicate, and reports an exception if there is not exactly one element in the async-enumerable sequence that matches the predicate. /// /// The type of elements in the source sequence. /// Source async-enumerable sequence. /// An asynchronous predicate that will be applied to each element of the source sequence. /// The optional cancellation token to be used for cancelling the sequence at any time. /// ValueTask containing the only element in the async-enumerable sequence that satisfies the condition in the asynchronous predicate. /// or is null. /// (Asynchronous) No element satisfies the condition in the predicate. -or- More than one element satisfies the condition in the predicate. -or- The source sequence is empty. public static ValueTask SingleAwaitAsync(this IAsyncEnumerable source, Func> predicate, CancellationToken cancellationToken = default) => SingleAwaitAsyncCore(source, predicate, cancellationToken); /// /// Returns the only element of an async-enumerable sequence that satisfies the condition in the asynchronous predicate, or a default value if no such element exists, and reports an exception if there is more than one element in the async-enumerable sequence that matches the predicate. /// /// The type of elements in the source sequence. /// Source async-enumerable sequence. /// An asynchronous predicate that will be applied to each element of the source sequence. /// The optional cancellation token to be used for cancelling the sequence at any time. /// ValueTask containing the only element in the async-enumerable sequence that satisfies the condition in the asynchronous predicate, or a default value if no such element exists. /// or is null. /// (Asynchronous) More than one element satisfies the condition in the predicate. public static ValueTask SingleOrDefaultAwaitAsync(this IAsyncEnumerable source, Func> predicate, CancellationToken cancellationToken = default) => SingleOrDefaultAwaitAsyncCore(source, predicate, cancellationToken); /// /// Bypasses elements in an async-enumerable sequence as long as a condition is true, and then returns the remaining elements. /// /// The type of elements in the source sequence. /// An async-enumerable sequence to return elements from. /// An asynchronous function to test each element for a condition. /// An async-enumerable sequence containing the elements in the source sequence starting at the first element that does not pass the test specified by the predicate. /// or is . public static IAsyncEnumerable SkipWhileAwait(this IAsyncEnumerable source, Func> predicate) => SkipWhileAwaitCore(source, predicate); /// /// Bypasses elements in an async-enumerable sequence as long as a condition is true, and then returns the remaining elements. /// The index of the element is used by the predicate. /// /// The type of elements in the source sequence. /// An async-enumerable sequence to return elements from. /// An asynchronous function to test each element for a condition; the second parameter of the function represents the index of the element. /// An async-enumerable sequence containing the elements in the source sequence starting at the first element that does not pass the test specified by the predicate. /// or is . public static IAsyncEnumerable SkipWhileAwait(this IAsyncEnumerable source, Func> predicate) => SkipWhileAwaitCore(source, predicate); /// /// Computes the sum of a sequence of values that are obtained by invoking a transform function on each element of the source sequence and awaiting the result. /// /// The type of elements in the source sequence. /// A sequence of values that are used to calculate a sum. /// An asynchronous transform function to apply to each element. /// The optional cancellation token to be used for cancelling the sequence at any time. /// A ValueTask containing the sum of the values in the source sequence. /// or is . /// The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior. public static ValueTask SumAwaitAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitAsyncCore(source, selector, cancellationToken); /// /// Computes the sum of a sequence of values that are obtained by invoking a transform function on each element of the source sequence and awaiting the result. /// /// The type of elements in the source sequence. /// A sequence of values that are used to calculate a sum. /// An asynchronous transform function to apply to each element. /// The optional cancellation token to be used for cancelling the sequence at any time. /// A ValueTask containing the sum of the values in the source sequence. /// or is . /// The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior. public static ValueTask SumAwaitAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitAsyncCore(source, selector, cancellationToken); /// /// Computes the sum of a sequence of values that are obtained by invoking a transform function on each element of the source sequence and awaiting the result. /// /// The type of elements in the source sequence. /// A sequence of values that are used to calculate a sum. /// An asynchronous transform function to apply to each element. /// The optional cancellation token to be used for cancelling the sequence at any time. /// A ValueTask containing the sum of the values in the source sequence. /// or is . /// The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior. public static ValueTask SumAwaitAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitAsyncCore(source, selector, cancellationToken); /// /// Computes the sum of a sequence of values that are obtained by invoking a transform function on each element of the source sequence and awaiting the result. /// /// The type of elements in the source sequence. /// A sequence of values that are used to calculate a sum. /// An asynchronous transform function to apply to each element. /// The optional cancellation token to be used for cancelling the sequence at any time. /// A ValueTask containing the sum of the values in the source sequence. /// or is . /// The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior. public static ValueTask SumAwaitAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitAsyncCore(source, selector, cancellationToken); /// /// Computes the sum of a sequence of values that are obtained by invoking a transform function on each element of the source sequence and awaiting the result. /// /// The type of elements in the source sequence. /// A sequence of values that are used to calculate a sum. /// An asynchronous transform function to apply to each element. /// The optional cancellation token to be used for cancelling the sequence at any time. /// A ValueTask containing the sum of the values in the source sequence. /// or is . /// The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior. public static ValueTask SumAwaitAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitAsyncCore(source, selector, cancellationToken); /// /// Computes the sum of a sequence of values that are obtained by invoking a transform function on each element of the source sequence and awaiting the result. /// /// The type of elements in the source sequence. /// A sequence of values that are used to calculate a sum. /// An asynchronous transform function to apply to each element. /// The optional cancellation token to be used for cancelling the sequence at any time. /// A ValueTask containing the sum of the values in the source sequence. /// or is . /// The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior. public static ValueTask SumAwaitAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitAsyncCore(source, selector, cancellationToken); /// /// Computes the sum of a sequence of values that are obtained by invoking a transform function on each element of the source sequence and awaiting the result. /// /// The type of elements in the source sequence. /// A sequence of values that are used to calculate a sum. /// An asynchronous transform function to apply to each element. /// The optional cancellation token to be used for cancelling the sequence at any time. /// A ValueTask containing the sum of the values in the source sequence. /// or is . /// The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior. public static ValueTask SumAwaitAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitAsyncCore(source, selector, cancellationToken); /// /// Computes the sum of a sequence of values that are obtained by invoking a transform function on each element of the source sequence and awaiting the result. /// /// The type of elements in the source sequence. /// A sequence of values that are used to calculate a sum. /// An asynchronous transform function to apply to each element. /// The optional cancellation token to be used for cancelling the sequence at any time. /// A ValueTask containing the sum of the values in the source sequence. /// or is . /// The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior. public static ValueTask SumAwaitAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitAsyncCore(source, selector, cancellationToken); /// /// Computes the sum of a sequence of values that are obtained by invoking a transform function on each element of the source sequence and awaiting the result. /// /// The type of elements in the source sequence. /// A sequence of values that are used to calculate a sum. /// An asynchronous transform function to apply to each element. /// The optional cancellation token to be used for cancelling the sequence at any time. /// A ValueTask containing the sum of the values in the source sequence. /// or is . /// The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior. public static ValueTask SumAwaitAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitAsyncCore(source, selector, cancellationToken); /// /// Computes the sum of a sequence of values that are obtained by invoking a transform function on each element of the source sequence and awaiting the result. /// /// The type of elements in the source sequence. /// A sequence of values that are used to calculate a sum. /// An asynchronous transform function to apply to each element. /// The optional cancellation token to be used for cancelling the sequence at any time. /// A ValueTask containing the sum of the values in the source sequence. /// or is . /// The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior. public static ValueTask SumAwaitAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitAsyncCore(source, selector, cancellationToken); /// /// Returns elements from an async-enumerable sequence as long as a specified condition is true. /// /// The type of the elements in the source sequence. /// A sequence to return elements from. /// An asynchronous predicate to test each element for a condition. /// An async-enumerable sequence that contains the elements from the input sequence that occur before the element at which the test no longer passes. /// or is null. public static IAsyncEnumerable TakeWhileAwait(this IAsyncEnumerable source, Func> predicate) => TakeWhileAwaitCore(source, predicate); /// /// Returns elements from an async-enumerable sequence as long as a specified condition is true. /// The element's index is used in the logic of the predicate function. /// /// The type of the elements in the source sequence. /// A sequence to return elements from. /// An asynchronous function to test each element for a condition; the second parameter of the function represents the index of the source element. /// An async-enumerable sequence that contains the elements from the input sequence that occur before the element at which the test no longer passes. /// or is null. public static IAsyncEnumerable TakeWhileAwait(this IAsyncEnumerable source, Func> predicate) => TakeWhileAwaitCore(source, predicate); /// /// Creates a dictionary from an async-enumerable sequence by invoking a key-selector function on each element and awaiting the result. /// /// The type of the elements in the source sequence. /// The type of the dictionary key computed for each element in the source sequence. /// An async-enumerable sequence to create a dictionary for. /// An asynchronous function to extract a key from each element. /// The optional cancellation token to be used for cancelling the sequence at any time. /// A ValueTask containing a dictionary mapping unique key values onto the corresponding source sequence's element. /// or is null. /// The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior. public static ValueTask> ToDictionaryAwaitAsync(this IAsyncEnumerable source, Func> keySelector, CancellationToken cancellationToken = default) where TKey : notnull => ToDictionaryAwaitAsyncCore(source, keySelector, cancellationToken); /// /// Creates a dictionary from an async-enumerable sequence by invoking a key-selector function on each element and awaiting the result. /// /// The type of the elements in the source sequence. /// The type of the dictionary key computed for each element in the source sequence. /// An async-enumerable sequence to create a dictionary for. /// An asynchronous function to extract a key from each element. /// An equality comparer to compare keys. /// The optional cancellation token to be used for cancelling the sequence at any time. /// A ValueTask containing a dictionary mapping unique key values onto the corresponding source sequence's element. /// or or is null. /// The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior. public static ValueTask> ToDictionaryAwaitAsync(this IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) where TKey : notnull => ToDictionaryAwaitAsyncCore(source, keySelector, comparer, cancellationToken); /// /// Creates a dictionary from an async-enumerable sequence using the specified asynchronous key and element selector functions. /// /// The type of the elements in the source sequence. /// The type of the dictionary key computed for each element in the source sequence. /// The type of the dictionary value computed for each element in the source sequence. /// An async-enumerable sequence to create a dictionary for. /// An asynchronous function to extract a key from each element. /// An asynchronous transform function to produce a result element value from each element. /// The optional cancellation token to be used for cancelling the sequence at any time. /// A ValueTask containing a dictionary mapping unique key values onto the corresponding source sequence's element. /// or or is null. /// The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior. public static ValueTask> ToDictionaryAwaitAsync(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, CancellationToken cancellationToken = default) where TKey : notnull => ToDictionaryAwaitAsyncCore(source, keySelector, elementSelector, cancellationToken); /// /// Creates a dictionary from an async-enumerable sequence using the specified asynchronous key and element selector functions. /// /// The type of the elements in the source sequence. /// The type of the dictionary key computed for each element in the source sequence. /// The type of the dictionary value computed for each element in the source sequence. /// An async-enumerable sequence to create a dictionary for. /// An asynchronous function to extract a key from each element. /// An asynchronous transform function to produce a result element value from each element. /// An equality comparer to compare keys. /// The optional cancellation token to be used for cancelling the sequence at any time. /// A ValueTask containing a dictionary mapping unique key values onto the corresponding source sequence's element. /// or or or is null. /// The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior. public static ValueTask> ToDictionaryAwaitAsync(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) where TKey : notnull => ToDictionaryAwaitAsyncCore(source, keySelector, elementSelector, comparer, cancellationToken); /// /// Creates a lookup from an async-enumerable sequence by invoking a key-selector function on each element and awaiting the result. /// /// The type of the elements in the source sequence. /// The type of the lookup key computed for each element in the source sequence. /// An async-enumerable sequence to create a lookup for. /// An asynchronous function to extract a key from each element. /// The optional cancellation token to be used for cancelling the sequence at any time. /// A ValueTask containing a lookup mapping unique key values onto the corresponding source sequence's elements. /// or is null. /// The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior. public static ValueTask> ToLookupAwaitAsync(this IAsyncEnumerable source, Func> keySelector, CancellationToken cancellationToken = default) => ToLookupAwaitAsyncCore(source, keySelector, cancellationToken); /// /// Creates a lookup from an async-enumerable sequence by invoking key and element selector functions on each source element and awaiting the results. /// /// The type of the elements in the source sequence. /// The type of the lookup key computed for each element in the source sequence. /// The type of the lookup value computed for each element in the source sequence. /// An async-enumerable sequence to create a lookup for. /// An asynchronous function to extract a key from each element. /// An asynchronous transform function to produce a result element value from each element. /// The optional cancellation token to be used for cancelling the sequence at any time. /// An async-enumerable sequence containing a single element with a lookup mapping unique key values onto the corresponding source sequence's elements. /// or or is null. /// The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior. public static ValueTask> ToLookupAwaitAsync(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, CancellationToken cancellationToken = default) => ToLookupAwaitAsyncCore(source, keySelector, elementSelector, cancellationToken); /// /// Creates a lookup from an async-enumerable sequence by invoking a key-selector function on each element and awaiting the result. /// /// The type of the elements in the source sequence. /// The type of the lookup key computed for each element in the source sequence. /// An async-enumerable sequence to create a lookup for. /// An asynchronous function to extract a key from each element. /// An equality comparer to compare keys. /// The optional cancellation token to be used for cancelling the sequence at any time. /// A ValueTask containing a lookup mapping unique key values onto the corresponding source sequence's elements. /// or or is null. /// The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior. public static ValueTask> ToLookupAwaitAsync(this IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) => ToLookupAwaitAsyncCore(source, keySelector, comparer, cancellationToken); /// /// Creates a lookup from an async-enumerable sequence by invoking key and element selector functions on each source element and awaiting the results. /// /// The type of the elements in the source sequence. /// The type of the lookup key computed for each element in the source sequence. /// The type of the lookup value computed for each element in the source sequence. /// An async-enumerable sequence to create a lookup for. /// An asynchronous function to extract a key from each element. /// An asynchronous transform function to produce a result element value from each source element. /// An equality comparer to compare keys. /// The optional cancellation token to be used for cancelling the sequence at any time. /// A ValueTask containing a lookup mapping unique key values onto the corresponding source sequence's elements. /// or or or is null. /// The return type of this operator differs from the corresponding operator on IEnumerable in order to retain asynchronous behavior. public static ValueTask> ToLookupAwaitAsync(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) => ToLookupAwaitAsyncCore(source, keySelector, elementSelector, comparer, cancellationToken); /// /// Filters the elements of an async-enumerable sequence based on an asynchronous predicate. /// /// The type of the elements in the source sequence. /// An async-enumerable sequence whose elements to filter. /// An asynchronous predicate to test each source element for a condition. /// An async-enumerable sequence that contains elements from the input sequence that satisfy the condition. /// or is null. public static IAsyncEnumerable WhereAwait(this IAsyncEnumerable source, Func> predicate) => WhereAwaitCore(source, predicate); /// /// Filters the elements of an async-enumerable sequence based on an asynchronous predicate that incorporates the element's index. /// /// The type of the elements in the source sequence. /// An async-enumerable sequence whose elements to filter. /// An asynchronous predicate to test each source element for a condition; the second parameter of the function represents the index of the source element. /// An async-enumerable sequence that contains elements from the input sequence that satisfy the condition. /// or is null. public static IAsyncEnumerable WhereAwait(this IAsyncEnumerable source, Func> predicate) => WhereAwaitCore(source, predicate); /// /// Merges two async-enumerable sequences into one async-enumerable sequence by combining their elements in a pairwise fashion. /// /// The type of the elements in the first source sequence. /// The type of the elements in the second source sequence. /// The type of the elements in the result sequence, returned by the selector function. /// First async-enumerable source. /// Second async-enumerable source. /// An asynchronous function to invoke and await for each consecutive pair of elements from the first and second source. /// An async-enumerable sequence containing the result of pairwise combining the elements of the first and second source using the specified result selector function. /// or or is null. public static IAsyncEnumerable ZipAwait(this IAsyncEnumerable first, IAsyncEnumerable second, Func> selector) => ZipAwaitCore(first, second, selector); #if !NO_DEEP_CANCELLATION public static ValueTask SingleAwaitWithCancellationAsync(this IAsyncEnumerable source, Func> predicate, CancellationToken cancellationToken = default) => SingleAwaitWithCancellationAsyncCore(source, predicate, cancellationToken); public static ValueTask SingleOrDefaultAwaitWithCancellationAsync(this IAsyncEnumerable source, Func> predicate, CancellationToken cancellationToken = default) => SingleOrDefaultAwaitWithCancellationAsyncCore(source, predicate, cancellationToken); public static IAsyncEnumerable SkipWhileAwaitWithCancellation(this IAsyncEnumerable source, Func> predicate) => SkipWhileAwaitWithCancellationCore(source, predicate); public static IAsyncEnumerable SkipWhileAwaitWithCancellation(this IAsyncEnumerable source, Func> predicate) => SkipWhileAwaitWithCancellationCore(source, predicate); public static ValueTask SumAwaitWithCancellationAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitWithCancellationAsyncCore(source, selector, cancellationToken); public static ValueTask SumAwaitWithCancellationAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitWithCancellationAsyncCore(source, selector, cancellationToken); public static ValueTask SumAwaitWithCancellationAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitWithCancellationAsyncCore(source, selector, cancellationToken); public static ValueTask SumAwaitWithCancellationAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitWithCancellationAsyncCore(source, selector, cancellationToken); public static ValueTask SumAwaitWithCancellationAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitWithCancellationAsyncCore(source, selector, cancellationToken); public static ValueTask SumAwaitWithCancellationAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitWithCancellationAsyncCore(source, selector, cancellationToken); public static ValueTask SumAwaitWithCancellationAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitWithCancellationAsyncCore(source, selector, cancellationToken); public static ValueTask SumAwaitWithCancellationAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitWithCancellationAsyncCore(source, selector, cancellationToken); public static ValueTask SumAwaitWithCancellationAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitWithCancellationAsyncCore(source, selector, cancellationToken); public static ValueTask SumAwaitWithCancellationAsync(this IAsyncEnumerable source, Func> selector, CancellationToken cancellationToken = default) => SumAwaitWithCancellationAsyncCore(source, selector, cancellationToken); public static IAsyncEnumerable TakeWhileAwaitWithCancellation(this IAsyncEnumerable source, Func> predicate) => TakeWhileAwaitWithCancellationCore(source, predicate); public static IAsyncEnumerable TakeWhileAwaitWithCancellation(this IAsyncEnumerable source, Func> predicate) => TakeWhileAwaitWithCancellationCore(source, predicate); public static ValueTask> ToDictionaryAwaitWithCancellationAsync(this IAsyncEnumerable source, Func> keySelector, CancellationToken cancellationToken = default) where TKey : notnull => ToDictionaryAwaitWithCancellationAsyncCore(source, keySelector, cancellationToken); public static ValueTask> ToDictionaryAwaitWithCancellationAsync(this IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) where TKey : notnull => ToDictionaryAwaitWithCancellationAsyncCore(source, keySelector, comparer, cancellationToken); public static ValueTask> ToDictionaryAwaitWithCancellationAsync(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, CancellationToken cancellationToken = default) where TKey : notnull => ToDictionaryAwaitWithCancellationAsyncCore(source, keySelector, elementSelector, cancellationToken); public static ValueTask> ToDictionaryAwaitWithCancellationAsync(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) where TKey : notnull => ToDictionaryAwaitWithCancellationAsyncCore(source, keySelector, elementSelector, comparer, cancellationToken); public static ValueTask> ToLookupAwaitWithCancellationAsync(this IAsyncEnumerable source, Func> keySelector, CancellationToken cancellationToken = default) => ToLookupAwaitWithCancellationAsyncCore(source, keySelector, cancellationToken); public static ValueTask> ToLookupAwaitWithCancellationAsync(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, CancellationToken cancellationToken = default) => ToLookupAwaitWithCancellationAsyncCore(source, keySelector, elementSelector, cancellationToken); public static ValueTask> ToLookupAwaitWithCancellationAsync(this IAsyncEnumerable source, Func> keySelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) => ToLookupAwaitWithCancellationAsyncCore(source, keySelector, comparer, cancellationToken); public static ValueTask> ToLookupAwaitWithCancellationAsync(this IAsyncEnumerable source, Func> keySelector, Func> elementSelector, IEqualityComparer comparer, CancellationToken cancellationToken = default) => ToLookupAwaitWithCancellationAsyncCore(source, keySelector, elementSelector, comparer, cancellationToken); public static IAsyncEnumerable WhereAwaitWithCancellation(this IAsyncEnumerable source, Func> predicate) => WhereAwaitWithCancellationCore(source, predicate); public static IAsyncEnumerable WhereAwaitWithCancellation(this IAsyncEnumerable source, Func> predicate) => WhereAwaitWithCancellationCore(source, predicate); public static IAsyncEnumerable ZipAwaitWithCancellation(this IAsyncEnumerable first, IAsyncEnumerable second, Func> selector) => ZipAwaitWithCancellationCore(first, second, selector); #endif #endif } }