Skip to content

Add an Ordering given instance for named tuples #23379

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Jun 16, 2025

No description provided.

@bishabosha bishabosha added the needs-minor-release This PR cannot be merged until the next minor release label Jun 16, 2025
@odersky odersky removed the needs-minor-release This PR cannot be merged until the next minor release label Jun 16, 2025
@odersky
Copy link
Contributor Author

odersky commented Jun 16, 2025

I would classify it as a bug fix, so no minor release needed.

@sjrd
Copy link
Member

sjrd commented Jun 16, 2025

Er ... no? It's a new public, stable API. Our policy does not let us add this kind of thing in a patch release, since it can break source compatibility. In fact, it is quite likely to break source compatibility: users who were actively missing this may have introduced such a given instance in their codebase. Adding it in the std lib will cause an ambiguous implicit resolution.

This does require a minor release.

@odersky
Copy link
Contributor Author

odersky commented Jun 16, 2025

@sjrd It won't cause an ambiguity because users would have added the feature with an implicit import. And the likelihood that we introduce conflicts increases the longer we wait.

Comment on lines +132 to +134
given namedTupleOrdering: [N <: Tuple, V <: Tuple] => (ord: Ordering[V]) => Ordering[NamedTuple[N, V]]:
def compare(x: NamedTuple[N, V], y: NamedTuple[N, V]): Int =
ord.compare(x.toTuple, y.toTuple)
Copy link
Contributor

@JD557 JD557 Jun 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nitpick, but is it worth constructing this manually, when there's already a Ordering.by helper for situations like this?

given namedTupleOrdering: [N <: Tuple, V <: Tuple] => Ordering[V] => Ordering[NamedTuple[N, V]] =
  Ordering.by(_.toTuple)

Not that it makes much of a difference, but should be slightly less error prone (e.g. for sure the x and y won't be switched).

@SethTisue
Copy link
Member

SethTisue commented Jun 16, 2025

I think we should not add new API in patch releases, even if it seems tempting in a particular case such as this one. Adding new (non-experimental) API in patch releases is something we Simply Do Not Do. If we don't adhere to these rules then version numbers become meaningless and users are reduced to playing guessing games about what they mean.

We made it all the way from 3.0.0 to 3.7.1 without doing this (at least, I don't recall that we ever made any exceptions?). Let's not start now.

@odersky odersky added the needs-minor-release This PR cannot be merged until the next minor release label Jun 17, 2025
@odersky odersky added this to the 3.8.0 milestone Jun 17, 2025
@odersky
Copy link
Contributor Author

odersky commented Jun 17, 2025

OK, let's schedule for 3.8. We should approve it now so that it's ready to get in.

Copy link
Member

@noti0na1 noti0na1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGMT

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-minor-release This PR cannot be merged until the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants