Scala SortedMap - iteratorFrom & co 缺少对应项?

Scala SortedMap - iteratorFrom & co missing counterpart?

检索属于更大键的条目

我最近偶然发现了一个 SO question asking how to retrieve keys greater than a given key in a SortedMap. AfaIk, these SortedMap 值得注意的方法:

检索属于较小键的条目

为了检索小于给定键的键,您可以使用这些 SortedMap 方法 (afaIk):

问题:
为什么没有模拟方法 iteratorTokeysIteratorTovaluesIteratorTo
如果它们存在,它们将如何工作?:

开始固定在最低键,takeWhile 就足够了:

scala> val m = TreeMap((0 to 10) map (i => (i, ('a' + i).toChar)) : _*)
m: scala.collection.immutable.TreeMap[Int,Char] = Map(0 -> a, 1 -> b, 2 -> c, 3 -> d, 4 -> e, 5 -> f, 6 -> g, 7 -> h, 8 -> i, 9 -> j, 10 -> k)

scala> m.iterator.takeWhile(_._1 < 5)
res1: Iterator[(Int, Char)] = non-empty iterator

scala> .toList
res2: List[(Int, Char)] = List((0,a), (1,b), (2,c), (3,d), (4,e))