I am pretty new to Scala and Play Framework and I never saw the following parameter type before.
def IsAuthenticated(f: => String => Request[AnyContent] => Result)
What is confusing me is the f: =>
part. If that =>
weren't there I would think of it as a function that maps a String
to a Request
and then to a Result
.
In general, => A
is a by name parameter of type A. That means the parameter will only be evaluated if and when (and each time) it is used in the body of the function. Thus, f
is a by name parameter whose type is a function that takes a String
and returns a function from a Request[AnyContent]
to a Result
. Here is an example of how by name parameter are evaluated:
scala> def twice[A](a: =>A) = (a,a)
twice: [A](a: => A)(A, A)
scala> var i = 0
i: Int = 0
scala> twice {
| i += 1
| i
| }
res0: (Int, Int) = (1,2)
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