Depending on what you mean, there are several different options.
If you mean a key-value "value" pair, you can use something like
myMap.exists(_ == ("fish",3)) myMap.exists(_ == "fish" -> 3)
If you mean the value of a key-value pair, you can
myMap.values.exists(_ == 3) myMap.exists(_._2 == 3)
If you just want to check the key of a key-value pair, then
myMap.keySet.exists(_ == "fish") myMap.exists(_._1 == "fish") myMap.contains("fish")
Note that although tuple forms (for example, _._1 == "fish" ) end shorter, slightly longer forms more clearly express what you want to execute.
Rex Kerr May 13 '12 at 4:39 a.m. 2012-05-13 04:39
source share