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

unsorted should return the most specific type #11037

Closed
MasseGuillaume opened this issue Jul 25, 2018 · 1 comment
Closed

unsorted should return the most specific type #11037

MasseGuillaume opened this issue Jul 25, 2018 · 1 comment

Comments

@MasseGuillaume
Copy link

MasseGuillaume commented Jul 25, 2018

https://static.javadoc.io/org.scala-lang/scala-library/2.13.0-M4/index.html?search=unsorted

Currently unsorted return the base collection:

scala.collection.immutable.SortedMap[K, V]
unsorted: collection.Map[K, V]

I would prefer it returns the most specific collection since this method is needed for compatibility with < 2.13. In < 2.13 map, collect and flatMap returns the most specific unsorted type of the collection when it cannot find an implicit Ordering:

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

In order to cross-compile between 2.12 and 2.13 we could write the following:

import scala.collection.compat._

set.unsorted.map(x => A(x))

For 2.12, we add an extension method unsorted.

Related: scala/scala-collection-compat#95

@MasseGuillaume
Copy link
Author

I'm on it.

julienrf added a commit to scala/scala that referenced this issue Aug 1, 2018
Unsorted return the most precise collection (fix scala/bug#11037)
@julienrf julienrf added this to the 2.13.0-M5 milestone Aug 1, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants