Reputation: 16164
In scala, how would i declare & instantiate a map that returns a function (for the sake of argument? A function that accepts two variables, one a String, one an Int)?
I am envisioning:
val myMap = Map[String, (String,Int)=>Boolean](
WHAT GOES HERE???
)
Let's just map the string "a" to this cool function. I don't care much about what the function does - returns true, perhaps?
Upvotes: 2
Views: 132
Reputation:
you can do something like this:
val map = Map("key" -> { (str: String, n: Int) =>
str.indexOf(n) == -1
})
result:
> map: scala.collection.immutable.Map[String,(String, Int) => Boolean] = Map(key - <function2>)
Upvotes: 0
Reputation: 13959
Try this:
val myMap = Map[String, (String, Int) => Boolean](
"Test" -> ((s, i) => true)
)
Upvotes: 4