The underscore – Scala's Swiss army knife
The underscore is an amazing thing that comes in handy in many situations. Here are some uses of the underscore that we need to know about. We will deal with other exotic uses as we come across them.
A Scala method is a part of a class. A method has a name and a signature. You can also put annotations in a method. We have already seen the @tailrec
annotation in Chapter 3, Recursion and Chasing Your Own Tail.
On the other hand, a function in Scala is an object or, moreover, an object implementing one of the function traits. A one parameter function implements Function1, a two parameter function implements Function 2 and so on.
When we create a variable whose value is a function object and when we call this function, the call gets converted into a call to the apply method.
Methods in Scala are not values, but functions in Scala are values. And as we know, we can pass these around. A method can also be converted to a function through Eta expansion, which...