Reputation: 198218
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?
Upvotes: 4
Views: 226
Reputation: 1777
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.
Upvotes: 1
Reputation: 92036
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.
Upvotes: 10