Skip to content

Instantly share code, notes, and snippets.

@diegopacheco
Created January 7, 2012 21:43
Show Gist options
  • Select an option

  • Save diegopacheco/1576148 to your computer and use it in GitHub Desktop.

Select an option

Save diegopacheco/1576148 to your computer and use it in GitHub Desktop.
Scala Pattern Matcher Recursion
object RecursionMatcher extends App{
def factorial(i:BigInt):BigInt = i match {
case _ if i == 1 => i
case _ => i * factorial(i - 1)
}
for(i <- 1 to 10) printf("%s: %s\n", i, factorial(i))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment