123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199 |
- // Licensed to the .NET Foundation under one or more agreements.
- // The .NET Foundation licenses this file to you under the Apache 2.0 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
- {
- public static partial class AsyncEnumerable
- {
- public static Task<ILookup<TKey, TSource>> ToLookupAsync<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector)
- {
- if (source == null)
- throw Error.ArgumentNull(nameof(source));
- if (keySelector == null)
- throw Error.ArgumentNull(nameof(keySelector));
- return ToLookupCore(source, keySelector, x => x, comparer: null, CancellationToken.None);
- }
- public static Task<ILookup<TKey, TSource>> ToLookupAsync<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, CancellationToken cancellationToken)
- {
- if (source == null)
- throw Error.ArgumentNull(nameof(source));
- if (keySelector == null)
- throw Error.ArgumentNull(nameof(keySelector));
- return ToLookupCore(source, keySelector, x => x, comparer: null, cancellationToken);
- }
- public static Task<ILookup<TKey, TSource>> ToLookupAsync<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector)
- {
- if (source == null)
- throw Error.ArgumentNull(nameof(source));
- if (keySelector == null)
- throw Error.ArgumentNull(nameof(keySelector));
- return ToLookupCore<TSource, TKey, TSource>(source, keySelector, x => new ValueTask<TSource>(x), comparer: null, CancellationToken.None);
- }
- public static Task<ILookup<TKey, TSource>> ToLookupAsync<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, CancellationToken cancellationToken)
- {
- if (source == null)
- throw Error.ArgumentNull(nameof(source));
- if (keySelector == null)
- throw Error.ArgumentNull(nameof(keySelector));
- return ToLookupCore<TSource, TKey, TSource>(source, keySelector, x => new ValueTask<TSource>(x), comparer: null, cancellationToken);
- }
- public static Task<ILookup<TKey, TSource>> ToLookupAsync<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
- {
- if (source == null)
- throw Error.ArgumentNull(nameof(source));
- if (keySelector == null)
- throw Error.ArgumentNull(nameof(keySelector));
- return ToLookupCore(source, keySelector, x => x, comparer, CancellationToken.None);
- }
- public static Task<ILookup<TKey, TSource>> ToLookupAsync<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
- {
- if (source == null)
- throw Error.ArgumentNull(nameof(source));
- if (keySelector == null)
- throw Error.ArgumentNull(nameof(keySelector));
- return ToLookupCore(source, keySelector, x => x, comparer, cancellationToken);
- }
- public static Task<ILookup<TKey, TSource>> ToLookupAsync<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer)
- {
- if (source == null)
- throw Error.ArgumentNull(nameof(source));
- if (keySelector == null)
- throw Error.ArgumentNull(nameof(keySelector));
- return ToLookupCore(source, keySelector, x => new ValueTask<TSource>(x), comparer, CancellationToken.None);
- }
- public static Task<ILookup<TKey, TSource>> ToLookupAsync<TSource, TKey>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
- {
- if (source == null)
- throw Error.ArgumentNull(nameof(source));
- if (keySelector == null)
- throw Error.ArgumentNull(nameof(keySelector));
- return ToLookupCore(source, keySelector, x => new ValueTask<TSource>(x), comparer, cancellationToken);
- }
- public static Task<ILookup<TKey, TElement>> ToLookupAsync<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector)
- {
- if (source == null)
- throw Error.ArgumentNull(nameof(source));
- if (keySelector == null)
- throw Error.ArgumentNull(nameof(keySelector));
- if (elementSelector == null)
- throw Error.ArgumentNull(nameof(elementSelector));
- return ToLookupCore(source, keySelector, elementSelector, comparer: null, CancellationToken.None);
- }
- public static Task<ILookup<TKey, TElement>> ToLookupAsync<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, CancellationToken cancellationToken)
- {
- if (source == null)
- throw Error.ArgumentNull(nameof(source));
- if (keySelector == null)
- throw Error.ArgumentNull(nameof(keySelector));
- if (elementSelector == null)
- throw Error.ArgumentNull(nameof(elementSelector));
- return ToLookupCore(source, keySelector, elementSelector, comparer: null, cancellationToken);
- }
- public static Task<ILookup<TKey, TElement>> ToLookupAsync<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TSource, ValueTask<TElement>> elementSelector)
- {
- if (source == null)
- throw Error.ArgumentNull(nameof(source));
- if (keySelector == null)
- throw Error.ArgumentNull(nameof(keySelector));
- if (elementSelector == null)
- throw Error.ArgumentNull(nameof(elementSelector));
- return ToLookupCore<TSource, TKey, TElement>(source, keySelector, elementSelector, comparer: null, CancellationToken.None);
- }
- public static Task<ILookup<TKey, TElement>> ToLookupAsync<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TSource, ValueTask<TElement>> elementSelector, CancellationToken cancellationToken)
- {
- if (source == null)
- throw Error.ArgumentNull(nameof(source));
- if (keySelector == null)
- throw Error.ArgumentNull(nameof(keySelector));
- if (elementSelector == null)
- throw Error.ArgumentNull(nameof(elementSelector));
- return ToLookupCore<TSource, TKey, TElement>(source, keySelector, elementSelector, comparer: null, cancellationToken);
- }
- 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)
- {
- if (source == null)
- throw Error.ArgumentNull(nameof(source));
- if (keySelector == null)
- throw Error.ArgumentNull(nameof(keySelector));
- if (elementSelector == null)
- throw Error.ArgumentNull(nameof(elementSelector));
- return ToLookupCore(source, keySelector, elementSelector, comparer, CancellationToken.None);
- }
- 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)
- {
- if (source == null)
- throw Error.ArgumentNull(nameof(source));
- if (keySelector == null)
- throw Error.ArgumentNull(nameof(keySelector));
- if (elementSelector == null)
- throw Error.ArgumentNull(nameof(elementSelector));
- return ToLookupCore(source, keySelector, elementSelector, comparer, cancellationToken);
- }
- public static Task<ILookup<TKey, TElement>> ToLookupAsync<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TSource, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer)
- {
- if (source == null)
- throw Error.ArgumentNull(nameof(source));
- if (keySelector == null)
- throw Error.ArgumentNull(nameof(keySelector));
- if (elementSelector == null)
- throw Error.ArgumentNull(nameof(elementSelector));
- return ToLookupCore(source, keySelector, elementSelector, comparer, CancellationToken.None);
- }
- public static Task<ILookup<TKey, TElement>> ToLookupAsync<TSource, TKey, TElement>(this IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TSource, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
- {
- if (source == null)
- throw Error.ArgumentNull(nameof(source));
- if (keySelector == null)
- throw Error.ArgumentNull(nameof(keySelector));
- if (elementSelector == null)
- throw Error.ArgumentNull(nameof(elementSelector));
- return ToLookupCore(source, keySelector, elementSelector, comparer, cancellationToken);
- }
- private static async Task<ILookup<TKey, TElement>> ToLookupCore<TSource, TKey, TElement>(IAsyncEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
- {
- return await Internal.Lookup<TKey, TElement>.CreateAsync(source, keySelector, elementSelector, comparer, cancellationToken).ConfigureAwait(false);
- }
- private static async Task<ILookup<TKey, TElement>> ToLookupCore<TSource, TKey, TElement>(IAsyncEnumerable<TSource> source, Func<TSource, ValueTask<TKey>> keySelector, Func<TSource, ValueTask<TElement>> elementSelector, IEqualityComparer<TKey> comparer, CancellationToken cancellationToken)
- {
- return await Internal.LookupWithTask<TKey, TElement>.CreateAsync(source, keySelector, elementSelector, comparer, cancellationToken).ConfigureAwait(false);
- }
- }
- }
|