get
is defined in CoreDsl as follows
def get(transformers: RouteTransformer*)(block: => Any): Route
So, get
takes two parameters, a sequence of route transformers (strings are implicitly converted into route transformers) and a parameterless method that outputs something of type Any
. The interesting part here is this second parameter.
The first thing to understand is that parameterless methods as function arguments are handled specially in Scala, namely as call-by-name, see Automatic Type-Dependent Closure Construction and also Scala Language Reference, Section 6.6, p. 78, which is p. 86 of the PDF:
The case of a formal parameter with a parameterless method type => T
is treated specially. In this case, the corresponding actual argument
expression e
is not evaluated before the application. Instead, every
use of the formal parameter on the right-hand side of the rewrite rule
entails a re-evaluation of e
. In other words, the evaluation order
for =>
-parameters is call-by-name whereas the evaluation order for
normal parameters is call-by-value.
The second aspect is that in function application, arguments can be enclosed either in ()
(the "regular" arguments) or {}
(more precisely, in this case they must be block expressions, and they can even start on a new line), see Scala Language Reference on Function Application, Section 6.6 on p. 77, which is p. 85 of the PDF.
Note also how these two features are a significant part of what makes Scala an attractive language for defining DSLs (or new keyword-like features).
Parts of the following question might also be interesting What's the difference between multiple parameters lists and multiple parameters per list in Scala?