I am new to Scala and tested the map function on the map. Here is my map:
scala> val map1 = Map ("abc" -> 1, "efg" -> 2, "hij" -> 3) map1: scala.collection.immutable.Map[String,Int] = Map(abc -> 1, efg -> 2, hij -> 3)
Here is the map function and the result:
scala> val result1 = map1.map(kv => (kv._1.toUpperCase, kv._2)) result1: scala.collection.immutable.Map[String,Int] = Map(ABC -> 1, EFG -> 2, HIJ -> 3)
Here is another map function and result:
scala> val result1 = map1.map(kv => (kv._1.length, kv._2)) result1: scala.collection.immutable.Map[Int,Int] = Map(3 -> 3)
The first map function returns all members as expected, but the second map function returns only the last member of the map. Can someone explain why this is happening?
Thanks in advance!
source share