We mentioned that Scala is a fusion of object-oriented and functional paradigms. Because of this, Scala has functions as a first-class element of the language. Also because of this, everything is an object in Scala. This is partly related to the fact that everything is an object or a primitive type in the JVM, but Scala goes further and also hides primitives behind objects.
It turns out that functions are also objects! Depending on the number of arguments, they extend one of the special traits. Also because of their object-oriented nature, it is possible to implement additional features by defining additional methods on the implementing class. This is how partial function is implemented. It is also natural to utilize companion objects to define common logic for functions so that it can be easily reused. It's even possible to write some...