September 2015
Intermediate to advanced
250 pages
6h 40m
English
In the previous example, the function values received one parameter. Function values can receive zero or more parameters. Let’s take a look at a few examples to learn how to define function values with different numbers of parameters.
In its simplest form, a function value may not even receive any parameter, but may return a result. Such a function value is like a factory—it constructs and returns an object. Let’s take a look at an example of defining and using a zero parameter function value:
| | def printValue(generator: () => Int) = { |
| | println(s"Generated value is ${generator()}") |
| | } |
| | |
| | printValue(() => 42) |
For the method printValue function, we’ve defined the parameter generator as a function ...
Read now
Unlock full access