I understand implicit parameters and implicit conversions in Scala but I saw this for the first time today: the implicit keyword in front of a parameter in an anonymous function:
Action { implicit request =>
Ok("Got request [" + request + "]")
}
What does the implicit keyword do here?
Are there resources on the web that describes more on what the use case is?
There are two distinct features here.
First,
requestisn’t really an argument in a method invocation. It’s the argument of an anonymous function. The anonymous function itself is the argument of the method invocation.Second, declaring an implicit argument in an anonymous function have the convenience of saving you from “forcing” a val into a implicit:
I happen to know this a Play framework code, but I am not sure what are the signatures for Action and Ok. I will guess that they are something like that:
Again, it’s pure guessing for illustrative purposes only.