Kotlins SortedMap is "a map that further provides a total ordering on its keys."
As a result, it should be indexable. However, this extension doesn't exist
`sortedMap.forEachIndexed()`
Why not? Am i overlooking something? Is it performance reasons? Didn't anyone bother?
(Yes, i know, i could use a List<Pair<Key, Value>>, but that's doesn't feel like the "intuitive" structure for my usecase, a map fits much better)
Most of the things that have a
forEachIndexedget it either fromIterableor have it as an extension function.Mapdoes not, but one of its properties, theentriesis actually aSet, which does haveforEachIndexedbecause it inherits fromCollection(which inherits fromIterable).That means that you can do something like this:
The reason I've added this to the already existing
asIterable().forEachIndexanswer, is becauseasIterable()creates a new object.