There is a special case of a function calling another function—the function calling itself. Such functions are called recursive. Recursive functions can be head-recursive or tail-recursive. There is also an approach to model recursive calls in an object-oriented way called trampolining. Recursion is very convenient and often uses the technique in functional programming, so let's take a close look at these concepts.
Recursion and trampolining
Recursion
Recursion is used to implement recurring logic without relying on loops and the internal states associated with them. The recursive behavior is defined by two properties:
- Base case: The simplest terminating case, in which no recursive calls are needed anymore
- Recursive...