Daniele B
05/18/2021, 9:52 AMval a = mapOf(2 to "W", 3 to "V", 1 to "T")
desired result:
val list = listOf("T","W","V")
I was reading you can do that using sortedMap
, but it doesn’t come out on the IDE.eHelg
05/18/2021, 9:57 AMval a = mapOf(2 to "W", 3 to "V", 1 to "T")
val arranged = a.values.sorted()
or
val a = mapOf(2 to "W", 3 to "V", 1 to "T")
val arranged = a.values.sortedBy { /* your logic here */ }
?val a = mapOf(2 to "W", 3 to "V", 1 to "T")
val arranged = a.toSortedMap().values
Daniele B
05/18/2021, 10:01 AMtoSortedMap()
doesn’t come up.
Maybe because I am using MultiPlaform?eHelg
05/18/2021, 10:05 AMval a = mapOf(2 to "W", 3 to "V", 1 to "T")
val arranged = a.toList().sortedBy { it.first }.map { it.second }
But might make more sense digging into why sortedMap doesn't workwbertan
05/18/2021, 10:05 AMtoSortedMap
extension just does this:
public fun <K : Comparable<K>, V> Map<out K, V>.toSortedMap(): SortedMap<K, V> = TreeMap(this)
Daniele B
05/18/2021, 10:08 AMsortedMap
supported to work on MultiPlatform? uhh, that’s weird. It’s not there.val myMap = MutableMap<Int, MyObject> = mutableMapOf()
eHelg
05/18/2021, 10:09 AMwbertan
05/18/2021, 10:15 AMMichael Böiers
05/19/2021, 7:08 AMVampire
05/19/2021, 9:55 AMMichael Böiers
05/19/2021, 10:02 AMVampire
05/19/2021, 10:03 AMMichael Böiers
05/19/2021, 10:04 AMTobias Berger
05/19/2021, 10:54 AMMichael Böiers
05/19/2021, 10:58 AMTobias Berger
05/19/2021, 11:31 AM