February 2018
Intermediate to advanced
552 pages
13h 46m
English
In previous sections, we defined a couple of Scala functions and came to know that each function has a meaningful name. Is it possible to define a function without a name? Yes, in Scala, we can define a function without a name.
An anonymous function is a function without a name. It is also known as a function literal. It works just like a normal function. Let's explore it with some examples now:
def add (a: Int, b: Int) = a + b
The following diagram shows the syntax of a Scala anonymous function:

As we discussed with the add() function in the previous section, it is a normal Scala function.
We can write the same ...
Read now
Unlock full access