Tail recursion
Briefly

Tail recursion is a form of recursion where the recursive call is the final operation, allowing compilers to optimize for memory efficiency, akin to loops.
Regular recursion adds new frames to the call stack, potentially causing a stack overflow. In contrast, tail recursion reuses the current function's stack frame.
In our factorial example, the helper function loop uses an accumulator to store the result, maintaining efficiency by applying tail recursion principles.
The Scala compiler optimizes tail recursion, enabling it to eliminate additional stack frames and prevent memory overflow issues, enhancing overall performance.
Read at Medium
[
]
[
|
]