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

SeqMap.keys is Seq [ci: last-only] #10766

Open
wants to merge 3 commits into
base: 2.13.x
Choose a base branch
from

Conversation

som-snytt
Copy link
Contributor

Fixes scala/bug#12991

Ensure that keys of a SeqMap is a Seq.

That satisfies the unwritten expectation that keys is ordered and mutually comparable.

@scala-jenkins scala-jenkins added this to the 2.13.15 milestone Apr 29, 2024
@som-snytt
Copy link
Contributor Author

@lrytz deprecated overriding of SeqMap#keys may have been hasty. IF it is useful (a big IF), it is usefully specialized. WDYT?

#10544

@SethTisue SethTisue requested a review from a team April 29, 2024 23:57
@SethTisue SethTisue added the library:collections PRs involving changes to the standard collection library label Apr 29, 2024
@som-snytt som-snytt marked this pull request as ready for review April 30, 2024 05:46
@lrytz
Copy link
Member

lrytz commented Apr 30, 2024

I think either keys is an alais of keySet, or we guarantee additional properties. I assume these would be "strict copy" and "same iteration order for ordered / sorted maps"? Maybe we can add overrides that reutrn Seq after SIP-51, but even without that the properties can be expressed in scaladoc and tests, and it's clear whether something is a bug or not.

Doing something in between can probably avoid some surprises but not really prevent bugs.

@som-snytt
Copy link
Contributor Author

Not sure if lrytz agreed to undeprecate, so I pushed it as a separate commit, unsquashed. Sorry, Jenkins.

To be clear, this PR was motivated by Ichoran's endorsement on the ticket, that even if keys is not (yet) Seq, go ahead and change it to return one anyway, as nobody could possibly be relying on the current behavior.

with nobody being the wiser for it

I can report that I do not feel wiser.

@lrytz
Copy link
Member

lrytz commented May 8, 2024

I see the point that returning a Seq doesn't hurt and can prevent surprises.

But if we don't actually guarantee anything then the value is very limited, surprises when using keys are just delayed.

I think either keys should be a final / deprecatedOverriding alias, or it should have documented properties that clients can rely on, anything in between is useful only by accident. But changing keys to always return a strict Seq copy is a (performance) breaking change, so it's not clear whether we can do that.

@som-snytt
Copy link
Contributor Author

som-snytt commented May 8, 2024

This is only for SeqMaps that don't yet override. It could be restricted further to SeqMap1..4, to be more conservative.

Then we can sort whether it's useful API etc under SIP-51.

Otherwise, I'll have to at-notify Ichoran.

@som-snytt som-snytt changed the title SeqMap.keys is Seq SeqMap.keys is Seq [ci: last-only] May 8, 2024
@som-snytt
Copy link
Contributor Author

it's not clear what the API intends:

      assertEquals(/*"Expect the same keys to appear in the join taken either way around.",*/
        ourChanges.mergeByKey(theirChangesRedux).keySet,
        theirChangesRedux.mergeByKey(ourChanges).keys,
      )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
library:collections PRs involving changes to the standard collection library
Projects
None yet
5 participants