I am trying to filter a map from strings to ints in scala and I am having a strange problem.
If I put the following in the REPL:
scala> val myMap = Map("a" -> 1, "b" -> 2, "c" -> 3) myMap: scala.collection.immutable.Map[java.lang.String,Int] = | Map(a -> 1, b -> 2, c -> 3)
So far this is normal, and it works ...
scala> myMap.filter(_._2 > 1) res9: scala.collection.immutable.Map[java.lang.String,Int] = Map(b -> 2, c -> 3)
but it fails ...
scala> myMap.filter((k:java.lang.String, v:Int) => v > 1) <console>:9: error: type mismatch; found : (java.lang.String, Int) => Boolean required: ((java.lang.String, Int)) => Boolean myMap.filter((k:java.lang.String, v:Int) => v > 1)
My question is what happens with the error message and an extra pair of parentheses? If I try to insert an additional set of parentheses, I get an error: not a formal formal parameter.
source share