https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
r

Raed Ghazal

09/23/2023, 1:36 PM
Hey I have the below code, the output is java SortedMap, is there a replacement for it in kotlin?
Copy code
val order = Status.values().asList()

statuses
    .groupingBy { it }
    .eachCount()
    .toSortedMap { t, t2 ->
        order.indexOf(t) - order.indexOf(t2)
    }
s

Spoudel347

09/23/2023, 1:54 PM
There is no sorted map on kotlin. You can do something like this, do verify before using it though.
Copy code
val order = Status.entries.toList()
  
  statuses
    .groupingBy { it }
    .eachCount()
    .map { it.key to it.value }
    .sortedBy {
      order.indexOf(it.first)
    }.toMap()
r

Raed Ghazal

09/23/2023, 1:55 PM
yeah thats what I ended up doing, thanks!