I see this scala function declaration in somewhere:
def test(f: => String => Result[AnyContent] => Result) = ...
I never saw this kind of function: => ... => ... => ..., how to understand it?
String => Result[AnyContent] => Result desugars to Function1[String, Function1[Result[AnyContent], Result]]. It's helpful to read it as: => String => (Result[AnyContent] => Result]). That is, a function that takes a => String returns a function Result[AnyContent] => Result (also known as curried function).
=> A is a by-name parameter of type A. So => String => Result[AnyContent] => Result indicates that test takes an argument of type String => Result[AnyContent] => Result by-name. Learn more about by-name parameters here.
Remember that a function is a normal data type. Functions can return functions.
f: => String => Result[AnyContent] => Result
Is the same as
String => ( Result[AnyContent] => Result )
This is just a function from String returning a function from Result[AnyContent] to Result.
f: => is a by name parameter as explained by Josh in the answer above.
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