-
Notifications
You must be signed in to change notification settings - Fork 18k
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
proposal: cmp: add Reverse function #65632
Comments
Just want to note that Rust has this; https://doc.rust-lang.org/std/cmp/struct.Reverse.html . |
The 'sort' package already has a Reverse function for sort.Interface, so a Reverse function for the 'cmp' package would fit well in analogy. https://pkg.go.dev/sort#Reverse |
I don't think |
@itchyny: You're right. I'll update the proposal. |
Just pondering here, should the implementation be |
@randall77: It's a fair thing to ponder. I believe they're equivalent. Let
The sign of
I quite like the implementation that swaps the arguments as it gets quite directly to the duality, but I'm not totally wedded to it. |
Proposal Details
I propose a small, trivial addition to the cmp package. (Ed.: This now incorporates an observation from @itchyny here.)
As an example,
prints out
I've found that it's frequently useful to want to assert that something is ordered ascending or descending; writing such a thing down is trivial but feels rather clumsy.
I'm happy to contribute a pull request with tests if this is considered a good idea.
The text was updated successfully, but these errors were encountered: