Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LastOrDefault on Min/MaxBy returns first #760

Closed
atifaziz opened this issue Aug 14, 2020 · 0 comments · Fixed by #761
Closed

LastOrDefault on Min/MaxBy returns first #760

atifaziz opened this issue Aug 14, 2020 · 0 comments · Fixed by #761
Assignees
Labels
Milestone

Comments

@atifaziz
Copy link
Member

Chaining MoreLINQ's LastOrDefault with MinBy or MaxBy returns the first element instead of the last one.

Below is a sample to reproduce the bug:

// Assuming:
// using MoreLinq;

var strings = new[]
{
    "foo", "bar", "baz", "qux", "quux", "quuz", "corge",
    "grault", "garply", "waldo", "fred", "plugh", "xyzzy", "thud"
};

Console.WriteLine("=== MinBy ===");
Console.WriteLine(strings.MinBy(s => s.Length).Last());
Console.WriteLine(strings.MinBy(s => s.Length).LastOrDefault());
Console.WriteLine("=== MaxBy ===");
Console.WriteLine(strings.MaxBy(s => s.Length).Last());
Console.WriteLine(strings.MaxBy(s => s.Length).LastOrDefault());

Expected:

=== MinBy ===
qux
qux
=== MaxBy ===
garply
garply

Instead, actual result when using version 3.3.2 (latest at time of reporting):

=== MinBy ===
qux
foo
=== MaxBy ===
garply
grault
@atifaziz atifaziz added the bug label Aug 14, 2020
@atifaziz atifaziz added this to the 3.4.0 milestone Aug 14, 2020
@atifaziz atifaziz self-assigned this Aug 14, 2020
@atifaziz atifaziz linked a pull request Aug 14, 2020 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant