scala - useless implicit keyword assigned to method ? / Play framework 2 -
as official documentation of play framework recommends, can use implicit request
in order improve access objects associated request.
sample:
def index = action { implicit request => session.get("connected").map { user => ok("hello " + user) }.getorelse { unauthorized("oops, not connected") } }
this due addition of following implicit
method belonged controller
trait:
/** * retrieves session implicitly request. * * example: * {{{ * def index(name:string) = action { implicit request => * val username = session("username") * ok("hello " + username) * } * }}} */ implicit def session(implicit request: requestheader) = request.session
question: why method declared implicit
? isn't enough declare request
parameter implicit
?
i expected see instead:
def session(implicit request: requestheader) = request.session
the first implicit
keyword indeed not necessary @ allow sample compile. either error in play!, or additional implicit
keyword intended play role.
in particular additional implicit
keyword, can call method expects implicit value of type session
if have implicit value of type requestheader
in scope (session
defines implicit value of type requestheader
, provided have implicit value of type requestheader
in scope).
Comments
Post a Comment