Running LINQ to Objects GroupBy() method for many items (gigabytes) can be memory consuming. If the IEnumerable<T> is already ordered by the key, we could write an GroupBy that didn’t consume as much memory.
Where can I find a library that has such method?
There’s nothing in the framework to do this. If you don’t need an actual
IGrouping<,>you could use this:If you need a full
IGrouping<,>implementation it’ll be slightly harder – but you could always grab my Edulinq implementation.The implementation of
GroupByChangeswould change very little – just change thecurrentListassignments to pass in the key to theGroupingconstructor: