W3cubDocs

/Kotlin

mapValues

Platform and version requirements: JVM (1.0), JS (1.0), Native (1.0)
inline fun <K, V, R> Map<out K, V>.mapValues(
    transform: (Entry<K, V>) -> R
): Map<K, R>

Returns a new map with entries having the keys of this map and the values obtained by applying the transform function to each entry in this Map.

The returned map preserves the entry iteration order of the original map.

import kotlin.test.*
import java.util.*

fun main(args: Array<String>) {
//sampleStart
val map1 = mapOf("beverage" to 2.7, "meal" to 12.4)
val map2 = map1.mapValues { it.value.toString() + "$" }

println(map2) // {beverage=2.7$, meal=12.4$}
//sampleEnd
}

© 2010–2019 JetBrains s.r.o.
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/map-values.html