I have the following map extension
object ImplicitMap {
implicit def extendMap(m : Map[String,Any]) = new MapExtension(m)
}
class MapExtension(m : Map[String,Any]) {
def +?(conditional:Boolean)(pair:(String,Any)):Map[String,Any] =
if (conditional) m + pair
else m
}
this function, when used gives the compile time error of Boolean does not take parameters, however a written explicit test (as follows) works correctly
test ("Map +?") {
def +?(conditional:Boolean)(pair:(String,Any)):Map[String,Any] = if (conditional) Map.empty + pair else Map.empty
+?(true)("hi" -> 2) should equal (Map("hi" -> 2))
}
I assume you are trying to write
someMap +? (cond)(pair), but that will not work, as it will be evaluate tosomeMap.+?(cond(pair)), you have to use it as a normal method, not as an operator.someMap.+?(cond)(pair)works for me.