I'm trying to get this Recursive Function to work:
@tailrec
def rec(n: BigInt): BigInt = {
if (n == 0) 0
else if (n == 1) 1
else (rec(n - 1) + rec(n - 2))
}
Error:(13, 24) could not optimize @tailrec annotated method rec: it contains a recursive call not in tail position else (rec(n - 1) + rec(n - 2))
How can this be optimized to work with tailrec?