Skip to content

Conversation

eiriktsarpalis
Copy link
Member

@eiriktsarpalis eiriktsarpalis commented Nov 9, 2021

Following the null handling semantics of the Max and Min methods, the new MaxBy and MinBy methods have been designed to skip any elements yielding null keys. As a side-effect of the behavior, the methods will return the last element in a sequence if every key turns out to be null. While this does not produce any observable difference in the Max and Min methods, it does do so in the MaxBy and MinBy case. In fact it is inconsistent with how the same methods treat sequences returning identical non-null keys, where the first element is always favored.

I do not believe this to be a breaking change, since our documentation provides no guarantee on what element will get returned in the event of a tie.

Fixes #61317.

@eiriktsarpalis eiriktsarpalis added this to the 7.0.0 milestone Nov 9, 2021
@eiriktsarpalis eiriktsarpalis self-assigned this Nov 9, 2021
@ghost
Copy link

ghost commented Nov 9, 2021

Tagging subscribers to this area: @dotnet/area-system-linq
See info in area-owners.md if you want to be subscribed.

Issue Details

Following the null handling semantics of the Max and Min methods, the new MaxBy and MinBy methods have been designed to skip any elements yielding null keys. As a side-effect of the behavior, the methods will return the last element in a sequence if every key turns out to be null. While this does not produce any observable difference in the Max and Min methods, it does do so in the MaxBy and MinBy. In fact it is inconsistent with how the same methods treat sequences returning identical non-null keys, where the first element is always favored.

I do not believe this change to be a breaking change, since our documentation provides no guarantee on what element will get returned in the event of a tie.

Author: eiriktsarpalis
Assignees: eiriktsarpalis
Labels:

area-System.Linq

Milestone: 7.0.0

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MaxBy inconsistent results with tie-breaks

2 participants