July 2018
Intermediate
186 pages
3h 24m
English
Now, we'll look at how function calls are implemented in Scala.
Scala provides flexible syntax and it is worth dedicating a few minutes to this concept.
The following is
a function,
f(a:Int, b:Int). We can call this
function using the named parameter syntax:
f(a = 5, b=10). If we swap the parameters but leave the correct names, the method will still be correct.
It is possible to combine positional and named function calls—the first few arguments can be positional.
For example:
def f(x:Int, y:Int) = x*2 + y f(x=1,y=2) // 4 f(y=1,x=2) // 5
When specifying a function, we can set default parameters. Then, later, when we call this function, we can omit parameters and the compiler will substitute ...
Read now
Unlock full access