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
https://static.javadoc.io/org.scala-lang/scala-library/2.13.0-M4/index.html?search=unsorted
Currently
unsortedreturn the base collection:I would prefer it returns the most specific collection since this method is needed for compatibility with < 2.13. In < 2.13
map,collectandflatMapreturns the most specific unsorted type of the collection when it cannot find an implicit Ordering:In order to cross-compile between 2.12 and 2.13 we could write the following:
For 2.12, we add an extension method
unsorted.Related: scala/scala-collection-compat#95