https://kotlinlang.org logo
#kotlin-native
Title
# kotlin-native
d

Dirk Hoffmann

11/03/2023, 2:47 PM
How would I best achieve something similar to java's
TreeMap
for non-jvm/native sourcecode? (or at least sort a MutableMap by key in non-jvm code)
r

ross_a

11/03/2023, 3:43 PM
If you need it to be sorted after each modification I'd probably pull in a JS lib and implement a MutableMap wrapper around it I don't know the JS landscape but something like https://www.npmjs.com/package/ncollections#SortedMap If you are only sorting once then
Copy code
val orderedMap = map.keys.sorted().associateWith { map[it] }
d

Dirk Hoffmann

11/03/2023, 3:44 PM
yes, that'll work for my case. Thanx. (actually not Js, but WasmJs where I did miss it, but also for native unix/MacOS/windows)
r

ross_a

11/03/2023, 3:45 PM
sorry don't know why I assumed JS