Since this is scala-user even though John has got his answer I'll
throw out what's going on in case it's helpful to anyone else.
The scala collection library tries to return a result of the same
"shape" as the original collection. (Hard enough that I can't ever
remember bumping into a corner case where it didn't but presumably if
you got really out there you could find one.) What this means is if
you map over a List you get back a List and over a Map you'd get back
a map. (If you want a new structure as a result it's much easier to
mess things up but google for "stackoverflow scala breakout" for the
gory details.)
Anyway John was mapping over a Map. Doing so hands a pair, Pair(key,
value), to your function. To get a map back from that the collections
library would really like you to work with it and return a Pair(key,
value) so it can update the map. The original example was only
returning an Int result. There are lots of ways to make this work but
in the spirit of the original
scala> Map("a" -> 1, "b" -> 2).map{case kv@(k,v) => if (k == "b") (k,v
+1) else kv}
res0: scala.collection.immutable.Map[java.lang.String,Int] = Map(a ->
1, b -> 3)
Enjoy,
-ljr