Functions represent another side of the blend of object-oriented and functional features in Scala. They can be defined in a number of ways, including the partial application of methods, function literals, and partial functions. Functions can be defined in any scope. If a function closes over variables available in scope, it is called closure.
Polymorphic functions implement an idea similar to polymorphism in object orientation, but apply that idea for types of parameters and of the result. This is called parametric polymorphism. It is especially useful when defining functions accepting other functions as arguments, so-called higher order functions.
There are two ways to implement recursion and only tail-recursive functions are stack safe in the JVM. For the functions which cannot be made tail-recursive, there is a way to represent the call chain in the heap by encoding...