|
| 1 | +namespace MyNihongo.LinqAsync; |
| 2 | + |
| 3 | +public static class ArrayTaskEx |
| 4 | +{ |
| 5 | + #region ToArray |
| 6 | + |
| 7 | + public static async Task<ImmutableArray<T>> ToImmutableArrayAsync<T>(this Task<T[]> @this) |
| 8 | + { |
| 9 | + var source = await @this.ConfigureAwait(false); |
| 10 | + return source.ToImmutableArray(); |
| 11 | + } |
| 12 | + |
| 13 | + #endregion |
| 14 | + |
| 15 | + #region ToDictionary |
| 16 | + |
| 17 | + public static async Task<IDictionary<TKey, TSource>> ToDictionaryAsync<TSource, TKey>(this Task<TSource[]> @this, Func<TSource, TKey> keySelector) |
| 18 | + where TKey : notnull |
| 19 | + { |
| 20 | + var source = await @this.ConfigureAwait(false); |
| 21 | + return source.ToDictionary(keySelector); |
| 22 | + } |
| 23 | + |
| 24 | + public static async Task<IDictionary<TKey, TSource>> ToDictionaryAsync<TSource, TKey>(this Task<TSource[]> @this, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> keyComparer) |
| 25 | + where TKey : notnull |
| 26 | + { |
| 27 | + var source = await @this.ConfigureAwait(false); |
| 28 | + return source.ToDictionary(keySelector, keyComparer); |
| 29 | + } |
| 30 | + |
| 31 | + public static async Task<IDictionary<TKey, TElement>> ToDictionaryAsync<TSource, TKey, TElement>(this Task<TSource[]> @this, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector) |
| 32 | + where TKey : notnull |
| 33 | + { |
| 34 | + var source = await @this.ConfigureAwait(false); |
| 35 | + return source.ToDictionary(keySelector, elementSelector); |
| 36 | + } |
| 37 | + |
| 38 | + public static async Task<IDictionary<TKey, TElement>> ToDictionaryAsync<TSource, TKey, TElement>(this Task<TSource[]> @this, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> keyComparer) |
| 39 | + where TKey : notnull |
| 40 | + { |
| 41 | + var source = await @this.ConfigureAwait(false); |
| 42 | + return source.ToDictionary(keySelector, elementSelector, keyComparer); |
| 43 | + } |
| 44 | + |
| 45 | + public static async Task<IImmutableDictionary<TKey, TSource>> ToImmutableDictionaryAsync<TSource, TKey>(this Task<TSource[]> @this, Func<TSource, TKey> keySelector) |
| 46 | + where TKey : notnull |
| 47 | + { |
| 48 | + var source = await @this.ConfigureAwait(false); |
| 49 | + return source.ToImmutableDictionary(keySelector); |
| 50 | + } |
| 51 | + |
| 52 | + public static async Task<IImmutableDictionary<TKey, TSource>> ToImmutableDictionaryAsync<TSource, TKey>(this Task<TSource[]> @this, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> keyComparer) |
| 53 | + where TKey : notnull |
| 54 | + { |
| 55 | + var source = await @this.ConfigureAwait(false); |
| 56 | + return source.ToImmutableDictionary(keySelector, keyComparer); |
| 57 | + } |
| 58 | + |
| 59 | + public static async Task<IImmutableDictionary<TKey, TElement>> ToImmutableDictionaryAsync<TSource, TKey, TElement>(this Task<TSource[]> @this, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector) |
| 60 | + where TKey : notnull |
| 61 | + { |
| 62 | + var source = await @this.ConfigureAwait(false); |
| 63 | + return source.ToImmutableDictionary(keySelector, elementSelector); |
| 64 | + } |
| 65 | + |
| 66 | + public static async Task<IImmutableDictionary<TKey, TElement>> ToImmutableDictionaryAsync<TSource, TKey, TElement>(this Task<TSource[]> @this, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> keyComparer) |
| 67 | + where TKey : notnull |
| 68 | + { |
| 69 | + var source = await @this.ConfigureAwait(false); |
| 70 | + return source.ToImmutableDictionary(keySelector, elementSelector, keyComparer); |
| 71 | + } |
| 72 | + |
| 73 | + public static async Task<IImmutableDictionary<TKey, TElement>> ToImmutableDictionaryAsync<TSource, TKey, TElement>(this Task<TSource[]> @this, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IEqualityComparer<TKey> keyComparer, IEqualityComparer<TElement> valueComparer) |
| 74 | + where TKey : notnull |
| 75 | + { |
| 76 | + var source = await @this.ConfigureAwait(false); |
| 77 | + return source.ToImmutableDictionary(keySelector, elementSelector, keyComparer, valueComparer); |
| 78 | + } |
| 79 | + |
| 80 | + public static async Task<IImmutableDictionary<TKey, TElement>> ToImmutableSortedDictionaryAsync<TSource, TKey, TElement>(this Task<TSource[]> @this, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector) |
| 81 | + where TKey : notnull |
| 82 | + { |
| 83 | + var source = await @this.ConfigureAwait(false); |
| 84 | + return source.ToImmutableSortedDictionary(keySelector, elementSelector); |
| 85 | + } |
| 86 | + |
| 87 | + public static async Task<IImmutableDictionary<TKey, TElement>> ToImmutableSortedDictionaryAsync<TSource, TKey, TElement>(this Task<TSource[]> @this, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IComparer<TKey> keyComparer) |
| 88 | + where TKey : notnull |
| 89 | + { |
| 90 | + var source = await @this.ConfigureAwait(false); |
| 91 | + return source.ToImmutableSortedDictionary(keySelector, elementSelector, keyComparer); |
| 92 | + } |
| 93 | + |
| 94 | + public static async Task<IImmutableDictionary<TKey, TElement>> ToImmutableSortedDictionaryAsync<TSource, TKey, TElement>(this Task<TSource[]> @this, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector, IComparer<TKey> keyComparer, IEqualityComparer<TElement> valueComparer) |
| 95 | + where TKey : notnull |
| 96 | + { |
| 97 | + var source = await @this.ConfigureAwait(false); |
| 98 | + return source.ToImmutableSortedDictionary(keySelector, elementSelector, keyComparer, valueComparer); |
| 99 | + } |
| 100 | + |
| 101 | + #endregion |
| 102 | + |
| 103 | + #region ToLookup |
| 104 | + |
| 105 | + public static async Task<ILookup<TKey, TElement>> ToLookupAsync<TSource, TKey, TElement>(this Task<TSource[]> @this, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector) |
| 106 | + { |
| 107 | + var source = await @this.ConfigureAwait(false); |
| 108 | + return source.ToLookup(keySelector, elementSelector); |
| 109 | + } |
| 110 | + |
| 111 | + #endregion |
| 112 | + |
| 113 | + #region Select |
| 114 | + |
| 115 | + public static async Task<IEnumerable<TResult>> Select<TSource, TResult>(this Task<TSource[]> @this, Func<TSource, TResult> selector) |
| 116 | + { |
| 117 | + var source = await @this.ConfigureAwait(false); |
| 118 | + return source.Select(selector); |
| 119 | + } |
| 120 | + |
| 121 | + #endregion |
| 122 | +} |
0 commit comments