I was trying to see if i could use the mapValues(p...
# getting-started
a
I was trying to see if i could use the mapValues(playing around with it to understand how it works) to transform the map for both the String and number(indicated by x and y) i had to use a combination of Destructing Declaration to be able to use the 2nd value which is y But i had to add a ";" i'm not too sure if this is the correct way, hope someone can advise me if this is correct
Copy code
val aMap= mapOf("one" to 1,"two" to 2)



fun main() {
    
    aMap.mapValues { (z,y)-> "$"+z;"$"+y }.forEach{z->println(z)}

}
s
Maybe you want something like this?
Copy code
aMap.entries.associate { (z, y) ->
   "$"+z to "$"+y
}
mapValues
will only change the values in the map, even though it receives both the key and the value in its inputs
The semicolon is not likely to be useful because it separates the line into two separate statements. The return value of a lambda function is always the final statement, so the part before the semicolon will actually end up being ignored.
When using
associate
you can instead use
to
to join the two parts into a
Pair
that’s returned in a single statement
a
Thank you @Sam