Last active
August 29, 2015 14:17
-
-
Save mrkaspa/9a5ca459d2599c6e520c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object RecursiveSum extends App { | |
println(sum(List(1, 2, 3, 10))) | |
def sum(nums: List[Int]): Int = { | |
@tailrec | |
def sumTail(x: Int, xs: List[Int]): Int = xs match { | |
case Nil => x | |
case y :: ys => sumTail(x + y, ys) | |
} | |
sumTail(0, nums) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment