- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Why is the result of scala.collection.immutable.TreeSet[A]#toString unsorted ?
Tue, 2010-05-25, 09:59
Hello. In scala 2.8.0.RC2 REPL, I noticed the following behavior:
scala> val ts = TreeSet("a", "b", "c", "d")
ts: scala.collection.immutable.TreeSet[java.lang.String] = TreeSet(a, b, c, d)
scala> val ts2 = ts + "e"
ts2: scala.collection.immutable.TreeSet[java.lang.String] =
TreeSet(e, a, b, c, d) // unsorted
Of course, I know it is not bug because ts.toList returns sortred list
correctly:
scala> ts2.toList
res0: List[java.lang.String] = List(a, b, c, d, e)
However, I think that this behavior is unkind. Because TreeSet
extends SortedSet, users of TreeSet
(include me) may expect that the result of toString is sorted. Then,
I hope that the result of
TreeSet[A]#toString is sorted. Is this demand incorrect?