The form parameter fn: => String is a "generator" (either a function or a value) that returns (or is) a String, so for example, you might have a method defined as
def myMethod(fn: => String): String = "Fn output = " + fn
and call it this way (the return types that I use here can usually be deduced by the compiler, I just add them for pedagogical purposes):
def myFn: String = "Hello!" // Alternatively: def myFn(): String = "Hello!" // or: val myFn: () => String = "Hello!" // or most simply: val myString = "Hello!" val output = myMethod(myFn) // output = "Fn output = Hello!"
Based on this, we can define a method that takes a function that turns String into Int, for example:
def my2ndMethod(fn: String => Int): Int = fn("4")
and name it as follows:
def my2ndFn(input: String) = 5 * input.toInt // Alternatively: val my2ndFn: String => Int = input => 5 * input.toInt val output2 = my2ndMethod(my2ndFn _) // output2 = 20
In case you provide, you have a more complex entity: that which returns (or is) a function that takes a string and returns an additional function, which in turn accepts Request[AnyContent] and (finally) returns the result ( phew!).
You can also think of it as a function assignment and use it as follows:
def authFn(username: String)(request: Request[AnyContent]): Result val authenticatedResult = IsAuthenticated(authFn _)
source share