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

Add SortedSet.unsorted and SortedMap.unsorted #95

Open
MasseGuillaume opened this issue Jul 13, 2018 · 5 comments
Open

Add SortedSet.unsorted and SortedMap.unsorted #95

MasseGuillaume opened this issue Jul 13, 2018 · 5 comments
Labels
good first issue Good for newcomers library Related to compat library code (not rewrite rules)

Comments

@MasseGuillaume
Copy link
Contributor

MasseGuillaume commented Jul 13, 2018

SortedSet.map in 2.12 returns a Set if it cannot find an implicit Ordering. To keep this behavior in 2.13, you can use unsorted. However, this method is not available in 2.12.

case class A(v: Int)
val set = collection.immutable.SortedSet(1)
set.map(x => A(x))
// Set(A(1)): Set[A] in 2.12
// error: No implicit Ordering defined for A. in 2.13
@julienrf
Copy link
Contributor

I think a cross-compatible workaround would be to explicitly upcast the sorted set: (TreeSet(1, 2): Set[Int]).map(f)

@MasseGuillaume
Copy link
Contributor Author

I think this is cleaner:

import compat._
TreeSet(1, 2).unsorted.map(f)

@MasseGuillaume
Copy link
Contributor Author

Unfortunately, this rewrite is going to be in the Experimental. Once again we hit scalameta/scalameta#1212.

Sorted collection have a special map functions that takes an ordering. The fallback map is defined in, for example, SetLike.map. We cannot make the difference between BitSet(1).map(f) and Set(1).map(f) since we don't know the type of the lhs (BitSet(1): BitSet and Set(1): Set[Int]). I think the short term solution for us is to fork scalameta's semanticdb.

@julienrf
Copy link
Contributor

I see. OK.

@julienrf julienrf added this to the Week 33 milestone Aug 10, 2018
@SethTisue SethTisue modified the milestones: Week 33, 2.13.0-RC1 Sep 18, 2018
@szeiger
Copy link
Contributor

szeiger commented Apr 5, 2019

Labeling as library. Adding the unsorted method in 2.12 should be the easiest solution for now.

@szeiger szeiger added the library Related to compat library code (not rewrite rules) label Apr 5, 2019
@dwijnand dwijnand removed this from the 2.13.0-RC1 milestone Jun 21, 2019
@SethTisue SethTisue added the good first issue Good for newcomers label Oct 28, 2022
martijnhoekstra pushed a commit to martijnhoekstra/scala-collection-compat that referenced this issue Nov 9, 2022
@SethTisue SethTisue changed the title Add SortedSet.unsorted and SortedMap.unsorted Add SortedSet.unsorted and SortedMap.unsorted Jun 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers library Related to compat library code (not rewrite rules)
Projects
None yet
Development

No branches or pull requests

5 participants