Skip to content

Instantly share code, notes, and snippets.

@davepkennedy
Created April 17, 2014 09:29
Show Gist options
  • Save davepkennedy/10968405 to your computer and use it in GitHub Desktop.
Save davepkennedy/10968405 to your computer and use it in GitHub Desktop.
Tailrec compliant Fibonacci seq in Scala
def fib (count: Int): Int = {
@tailrec def _fib (count: Int, value: Int, accum: Int = 0): Int = count match {
case 0 => accum
case _ => _fib(count - 1, accum, value + accum)
}
_fib(count, 1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment