While reading Play! Framework documentation, I came across this snippet:
def index = Action { implicit request => session.get("connected").map { user => Ok("Hello " + user) }.getOrElse { Unauthorized("Oops, you are not connected") } }
The documentationation explains implicit there:
Alternatively, you can get the session implicitly from the request
Also, I read this post: Literal with Implicit and it seems logical that a function cannot have an implicit parameter.
If I understand well, this is because a function , contrary to the method, always has a contract (interface).
In fact, for example, Function1[Int, Function1[Int, Int]] has the first parameter an Int as the return type, and thus allows us to annotate this text as implicit . This will lead to confusion regarding the high level return type: () => Int or Int => Int ...
Consequently, what the previous code of the fragment leads is implicit, since the first Action required parameter is a literal function.
I assume that the reason the compiler accepts this code is because of the multiple signatures of the Action.apply() method:
def apply(block: Request[AnyContent] => Result): Action[AnyContent]def apply(block: => Result): Action[AnyContent] (redirect to first)
Since the second one does not need any parameter, is this one chosen in the presence of an implicit parameter of a literal function?