Can someone explain the Scala code used in trait Secured of playframework sample app zentask:
def IsAuthenticated(f: => String => Request[AnyContent] => Result) = Security.Authenticated(username, onUnauthorized) { user =>
Action(request => f(user)(request))
}
I've just started to learn Scala and can not figure out this sequence f: => String => Request[AnyContent] => Result
. What does it mean? I can not find any examples in manuals that use several =>
in place of parameters list for function.
What am I missing?
Maybe it's easier if you add some parantheses:
f: => (String => (Request[AnyContent] => Result))
f
is a call-by-name parameter; it's a function that takes a String
and returns: a function that takes a Request[AnyContent]
and returns a Result
.
f
is a function that, given a String
will produce a function that waits for a Result[AnyContent]
to provide a Result
.
Then at line 2. you pass to f
the user
param, which must be a String
and you pass the request
param to the resulting function.
This way of passing parameters is called currying. A both short and a bit more complex example can be found there: http://www.scala-lang.org/node/135
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With