Can I map a list into two separate lists based on ...
# android
a
Can I map a list into two separate lists based on the fields?
Copy code
val list = listOf<Pair<Int, Int>>()
val (firstList, secondList) = ?? //how to do the mapping on the list here
a
It's not exactly what I look up, let me elaborate in a real example:
Copy code
data class User(id, name)
val list = List<User>()
val (ids, names) = list.? // I need to map the ids into the first list and the names into the second list
e.g.
Copy code
val (ids, names) = list.map { it.id to it.name }.unzip()
👌 1
a
Thanks man, that's what I'm looking for exactly!
493 Views