```listOf("banana").map { it to 42 }.toMap()``` is...
# announcements
l
Copy code
listOf("banana").map { it to 42 }.toMap()
is there an easier way to do this ? basically i want to turn a list into a map by providing a lambda that associates each element from the list with a value to form a key-value pair
s
look into the
associate*
family of functions
c
Copy code
listOf("banana").associate { it to 42 }
in this specific instance you’ll want
associateWith { 42 }
l
thanks
d
Or
mapOf("banana" to 42)
😛
🏆 3
😛 6