It looks like -- in Scala 2.8.0 -- if you map() a Map instance to a sequence of 2-tuples that you end up getting a Map back. When this happens, any of the 2-tuples with the same first element are considered duplicates, and you only end up getting the last one. This is different from what happened in 2.7.7. This is easier to understand with an example.
Scala 2.7.7:
scala> val m = Map("a" -> 1, "b" -> 2, "c" -> 3)
m: scala.collection.immutable.Map[java.lang.String,Int] = Map(a -> 1, b -> 2, c -> 3)
scala> m.map { case (k, v) => ("foo", v) }
res5: Iterable[(java.lang.String, Int)] = ArrayBuffer((foo,1), (foo,2), (foo,3))
Scala 2.8.0:
scala> val m = Map("a" -> 1, "b" -> 2, "c" -> 3)
m: scala.collection.immutable.Map[java.lang.String,Int] = Map((a,1), (b,2), (c,3))
scala> m.map { case (k, v) => ("foo", v) }
res16: scala.collection.immutable.Map[java.lang.String,Int] = Map((foo,3))
Is this expected? Is the change documented somewhere? It seems like a reasonable idea, but it has cost me a lot of time upgrading a 2.7.7 app that was relying on the old behaviour.
Update:
As pointed out below by Kris Nuttycombe, reading Migrating from Scala 2.7 might have been a good start before asking this question :) In particular it mentions using the compiler flag -Xmigration
, which seems extremely useful when porting.