Core concept
import scala.annotation.tailrec
@tailrec
def fact(n: Int, acc: Int = 1): Int =
if (n <= 1) acc else fact(n - 1, n * acc)Advertisement
How it works
Only self-recursion supported. Mutual recursion needs trampoline.
Advertisement
Trade-offs + gotchas
Recursive algorithms without stack overflow.