Open
Description
reproduction steps
using Scala 2.13.2
scala> collection.mutable.TreeMap(0->0).iterableFactory
val res0: scala.collection.IterableFactory[scala.collection.mutable.Iterable] = scala.collection.mutable.Iterable$@563843f1
scala> collection.immutable.TreeMap(0->0).iterableFactory
val res1: scala.collection.IterableFactory[scala.collection.immutable.Iterable] = scala.collection.immutable.Iterable$@3a988299
problem
Both mutable and immutable TreeMap
/SortedMap
's iterableFactory
return just a normal Iterable
. Although it currently works, because IterableFactory
is a Delegate of List
, it is
- conceptually incorrect. They are sorted in order, and iterableFactory should retain the sequential order.
Iterable
does not guarrantee the sorted order - if
Iterable
implemenetation changes in the future and no longerList
, this will break.
Furthermore, currently keySet
signature returns a SortedSet
, which is accurate, but values
returns a simple Iterable
. It would be more preferred to return a Seq
instead, so the values would also retain the order same as in the SortedMap