@@ -22,33 +22,36 @@ internal static class IncrementalValuesProviderExtensions
22
22
/// </summary>
23
23
/// <typeparam name="TLeft">The type of left items in each tuple.</typeparam>
24
24
/// <typeparam name="TRight">The type of right items in each tuple.</typeparam>
25
+ /// <typeparam name="TElement">The type of resulting projected elements.</typeparam>
25
26
/// <param name="source">The input <see cref="IncrementalValuesProvider{TValues}"/> instance.</param>
26
27
/// <param name="comparer">A <typeparamref name="TLeft"/> comparer.</param>
28
+ /// <param name="projection">A projection function to convert gathered elements.</param>
27
29
/// <returns>An <see cref="IncrementalValuesProvider{TValues}"/> with the grouped results.</returns>
28
- public static IncrementalValuesProvider < ( TLeft Left , ImmutableArray < TRight > Right ) > GroupBy < TLeft , TRight > (
30
+ public static IncrementalValuesProvider < ( TLeft Left , ImmutableArray < TElement > Right ) > GroupBy < TLeft , TRight , TElement > (
29
31
this IncrementalValuesProvider < ( TLeft Left , TRight Right ) > source ,
30
- IEqualityComparer < TLeft > comparer )
32
+ IEqualityComparer < TLeft > comparer ,
33
+ Func < TRight , TElement > projection )
31
34
{
32
35
return source . Collect ( ) . SelectMany ( ( item , _ ) =>
33
36
{
34
- Dictionary < TLeft , ImmutableArray < TRight > . Builder > map = new ( comparer ) ;
37
+ Dictionary < TLeft , ImmutableArray < TElement > . Builder > map = new ( comparer ) ;
35
38
36
39
foreach ( ( TLeft hierarchy , TRight info ) in item )
37
40
{
38
- if ( ! map . TryGetValue ( hierarchy , out ImmutableArray < TRight > . Builder builder ) )
41
+ if ( ! map . TryGetValue ( hierarchy , out ImmutableArray < TElement > . Builder builder ) )
39
42
{
40
- builder = ImmutableArray . CreateBuilder < TRight > ( ) ;
43
+ builder = ImmutableArray . CreateBuilder < TElement > ( ) ;
41
44
42
45
map . Add ( hierarchy , builder ) ;
43
46
}
44
47
45
- builder . Add ( info ) ;
48
+ builder . Add ( projection ( info ) ) ;
46
49
}
47
50
48
- ImmutableArray < ( TLeft Hierarchy , ImmutableArray < TRight > Properties ) > . Builder result =
49
- ImmutableArray . CreateBuilder < ( TLeft , ImmutableArray < TRight > ) > ( ) ;
51
+ ImmutableArray < ( TLeft Hierarchy , ImmutableArray < TElement > Elements ) > . Builder result =
52
+ ImmutableArray . CreateBuilder < ( TLeft , ImmutableArray < TElement > ) > ( ) ;
50
53
51
- foreach ( KeyValuePair < TLeft , ImmutableArray < TRight > . Builder > entry in map )
54
+ foreach ( KeyValuePair < TLeft , ImmutableArray < TElement > . Builder > entry in map )
52
55
{
53
56
result . Add ( ( entry . Key , entry . Value . ToImmutable ( ) ) ) ;
54
57
}
0 commit comments