Closed Brads3290 closed 2 years ago
Note: A workaround for now is to sort an iterable before grouping, because then there are no values between groups. Might be a performance issue in some circumstances though.
Workaround as an extension method.
extension DarqExtension<T> on Iterable<T> {
GroupByIterable<T, TKey> groupByHotfix<TKey>(
TKey Function(T element) keySelector, {
EqualityComparer<TKey>? keyComparer,
}) {
return this
.orderBy((e) => keySelector(e), keyComparer: keyComparer)
.groupBy((e) => keySelector(e), keyComparer: keyComparer);
}
}
Note: This executes keySelector
for both orderBy
and groupBy
.
Strange one, had me ripping my hair out for a while.
Take this example:
Expected output:
Actual output:
For some reason,
groupBy
is splittingZZ
into two groups. I've been playing around with this example and this seems to only happen when there are 7 or more distinct values placed between the ZZ values. Not sure what the significance of 7 is, but if I take any of those groups in the middle away, it correctly groups ZZ again.This seems to happen with any values too; I originally noticed the issue with a long list of ISO date strings in my application and simplified it down to this example.
Any thoughts?