22
33public static partial class AsyncLinq
44{
5- // TODO Reprendre tous les appels avec IEnumerable<TResult> et les dupliquer avec TResult[] et List<TResult>
6- // TODO Faire un test qui garantit qu'on n'ait pas d'ambiguité sur les appels sans devoir spécifier les types génériques
7- // TODO Valider qu'on est bien avec List et array
8-
95 public static async IAsyncEnumerable < TResult > SelectManyAsync < T , TResult > ( this IAsyncEnumerable < T > source , Func < T , IEnumerable < TResult > > selector , [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
106 {
117 await foreach ( var item in source . WithCancellation ( cancellationToken ) . ConfigureAwait ( false ) )
@@ -38,6 +34,17 @@ public static async IAsyncEnumerable<TResult> SelectManyAsync<T, TResult>(this I
3834 }
3935 }
4036
37+ public static async IAsyncEnumerable < TResult > SelectManyAsync < T , TResult > ( this IEnumerable < T > source , Func < T , Task < List < TResult > > > selector , [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
38+ {
39+ cancellationToken . ThrowIfCancellationRequested ( ) ;
40+ foreach ( var item in source )
41+ foreach ( var result in await selector ( item ) . ConfigureAwait ( false ) )
42+ {
43+ cancellationToken . ThrowIfCancellationRequested ( ) ;
44+ yield return result ;
45+ }
46+ }
47+
4148 public static async IAsyncEnumerable < TResult > SelectManyAsync < T , TResult > ( this IAsyncEnumerable < T > source , Func < T , Task < IEnumerable < TResult > > > selector , [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
4249 {
4350 await foreach ( var item in source . WithCancellation ( cancellationToken ) . ConfigureAwait ( false ) )
@@ -58,6 +65,16 @@ public static async IAsyncEnumerable<TResult> SelectManyAsync<T, TResult>(this I
5865 }
5966 }
6067
68+ public static async IAsyncEnumerable < TResult > SelectManyAsync < T , TResult > ( this IAsyncEnumerable < T > source , Func < T , Task < List < TResult > > > selector , [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
69+ {
70+ await foreach ( var item in source . WithCancellation ( cancellationToken ) . ConfigureAwait ( false ) )
71+ foreach ( var result in await selector ( item ) . ConfigureAwait ( false ) )
72+ {
73+ cancellationToken . ThrowIfCancellationRequested ( ) ;
74+ yield return result ;
75+ }
76+ }
77+
6178 public static async IAsyncEnumerable < TResult > SelectManyAsync < T , TResult > ( this IEnumerable < T > source , Func < T , IAsyncEnumerable < TResult > > selector , [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
6279 {
6380 cancellationToken . ThrowIfCancellationRequested ( ) ;
@@ -93,6 +110,26 @@ public static async IAsyncEnumerable<TResult> SelectManyAsync<T, TCollection, TR
93110 }
94111 }
95112
113+ public static async IAsyncEnumerable < TResult > SelectManyAsync < T , TCollection , TResult > ( this IAsyncEnumerable < T > source , Func < T , Task < TCollection [ ] > > collectionSelector , Func < T , TCollection , TResult > resultSelector , [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
114+ {
115+ await foreach ( var item in source . WithCancellation ( cancellationToken ) . ConfigureAwait ( false ) )
116+ foreach ( var result in await collectionSelector ( item ) . ConfigureAwait ( false ) )
117+ {
118+ cancellationToken . ThrowIfCancellationRequested ( ) ;
119+ yield return resultSelector ( item , result ) ;
120+ }
121+ }
122+
123+ public static async IAsyncEnumerable < TResult > SelectManyAsync < T , TCollection , TResult > ( this IAsyncEnumerable < T > source , Func < T , Task < List < TCollection > > > collectionSelector , Func < T , TCollection , TResult > resultSelector , [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
124+ {
125+ await foreach ( var item in source . WithCancellation ( cancellationToken ) . ConfigureAwait ( false ) )
126+ foreach ( var result in await collectionSelector ( item ) . ConfigureAwait ( false ) )
127+ {
128+ cancellationToken . ThrowIfCancellationRequested ( ) ;
129+ yield return resultSelector ( item , result ) ;
130+ }
131+ }
132+
96133 public static async IAsyncEnumerable < TResult > SelectManyAsync < T , TCollection , TResult > ( this IEnumerable < T > source , Func < T , Task < IEnumerable < TCollection > > > collectionSelector , Func < T , TCollection , TResult > resultSelector , [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
97134 {
98135 cancellationToken . ThrowIfCancellationRequested ( ) ;
@@ -104,6 +141,28 @@ public static async IAsyncEnumerable<TResult> SelectManyAsync<T, TCollection, TR
104141 }
105142 }
106143
144+ public static async IAsyncEnumerable < TResult > SelectManyAsync < T , TCollection , TResult > ( this IEnumerable < T > source , Func < T , Task < TCollection [ ] > > collectionSelector , Func < T , TCollection , TResult > resultSelector , [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
145+ {
146+ cancellationToken . ThrowIfCancellationRequested ( ) ;
147+ foreach ( var item in source )
148+ foreach ( var result in await collectionSelector ( item ) . ConfigureAwait ( false ) )
149+ {
150+ cancellationToken . ThrowIfCancellationRequested ( ) ;
151+ yield return resultSelector ( item , result ) ;
152+ }
153+ }
154+
155+ public static async IAsyncEnumerable < TResult > SelectManyAsync < T , TCollection , TResult > ( this IEnumerable < T > source , Func < T , Task < List < TCollection > > > collectionSelector , Func < T , TCollection , TResult > resultSelector , [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
156+ {
157+ cancellationToken . ThrowIfCancellationRequested ( ) ;
158+ foreach ( var item in source )
159+ foreach ( var result in await collectionSelector ( item ) . ConfigureAwait ( false ) )
160+ {
161+ cancellationToken . ThrowIfCancellationRequested ( ) ;
162+ yield return resultSelector ( item , result ) ;
163+ }
164+ }
165+
107166 public static async IAsyncEnumerable < TResult > SelectManyAsync < T , TCollection , TResult > ( this IEnumerable < T > source , Func < T , IAsyncEnumerable < TCollection > > collectionSelector , Func < T , TCollection , TResult > resultSelector , [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
108167 {
109168 cancellationToken . ThrowIfCancellationRequested ( ) ;
@@ -150,6 +209,26 @@ public static async IAsyncEnumerable<TResult> SelectManyAsync<T, TCollection, TR
150209 }
151210 }
152211
212+ public static async IAsyncEnumerable < TResult > SelectManyAsync < T , TCollection , TResult > ( this IAsyncEnumerable < T > source , Func < T , Task < TCollection [ ] > > collectionSelector , Func < T , TCollection , Task < TResult > > resultSelector , [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
213+ {
214+ await foreach ( var item in source . WithCancellation ( cancellationToken ) . ConfigureAwait ( false ) )
215+ foreach ( var result in await collectionSelector ( item ) . ConfigureAwait ( false ) )
216+ {
217+ cancellationToken . ThrowIfCancellationRequested ( ) ;
218+ yield return await resultSelector ( item , result ) . ConfigureAwait ( false ) ;
219+ }
220+ }
221+
222+ public static async IAsyncEnumerable < TResult > SelectManyAsync < T , TCollection , TResult > ( this IAsyncEnumerable < T > source , Func < T , Task < List < TCollection > > > collectionSelector , Func < T , TCollection , Task < TResult > > resultSelector , [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
223+ {
224+ await foreach ( var item in source . WithCancellation ( cancellationToken ) . ConfigureAwait ( false ) )
225+ foreach ( var result in await collectionSelector ( item ) . ConfigureAwait ( false ) )
226+ {
227+ cancellationToken . ThrowIfCancellationRequested ( ) ;
228+ yield return await resultSelector ( item , result ) . ConfigureAwait ( false ) ;
229+ }
230+ }
231+
153232 public static async IAsyncEnumerable < TResult > SelectManyAsync < T , TCollection , TResult > ( this IEnumerable < T > source , Func < T , Task < IEnumerable < TCollection > > > collectionSelector , Func < T , TCollection , Task < TResult > > resultSelector , [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
154233 {
155234 cancellationToken . ThrowIfCancellationRequested ( ) ;
@@ -161,6 +240,28 @@ public static async IAsyncEnumerable<TResult> SelectManyAsync<T, TCollection, TR
161240 }
162241 }
163242
243+ public static async IAsyncEnumerable < TResult > SelectManyAsync < T , TCollection , TResult > ( this IEnumerable < T > source , Func < T , Task < TCollection [ ] > > collectionSelector , Func < T , TCollection , Task < TResult > > resultSelector , [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
244+ {
245+ cancellationToken . ThrowIfCancellationRequested ( ) ;
246+ foreach ( var item in source )
247+ foreach ( var result in await collectionSelector ( item ) . ConfigureAwait ( false ) )
248+ {
249+ cancellationToken . ThrowIfCancellationRequested ( ) ;
250+ yield return await resultSelector ( item , result ) . ConfigureAwait ( false ) ;
251+ }
252+ }
253+
254+ public static async IAsyncEnumerable < TResult > SelectManyAsync < T , TCollection , TResult > ( this IEnumerable < T > source , Func < T , Task < List < TCollection > > > collectionSelector , Func < T , TCollection , Task < TResult > > resultSelector , [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
255+ {
256+ cancellationToken . ThrowIfCancellationRequested ( ) ;
257+ foreach ( var item in source )
258+ foreach ( var result in await collectionSelector ( item ) . ConfigureAwait ( false ) )
259+ {
260+ cancellationToken . ThrowIfCancellationRequested ( ) ;
261+ yield return await resultSelector ( item , result ) . ConfigureAwait ( false ) ;
262+ }
263+ }
264+
164265 public static async IAsyncEnumerable < TResult > SelectManyAsync < T , TCollection , TResult > ( this IEnumerable < T > source , Func < T , IAsyncEnumerable < TCollection > > collectionSelector , Func < T , TCollection , Task < TResult > > resultSelector , [ EnumeratorCancellation ] CancellationToken cancellationToken = default )
165266 {
166267 cancellationToken . ThrowIfCancellationRequested ( ) ;
0 commit comments