Created
July 17, 2013 09:55
-
-
Save tobyweston/6019269 to your computer and use it in GitHub Desktop.
Tail recursion in Sacala
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
import org.scalatest.FunSuite | |
class RecursionTest extends FunSuite { | |
case class Explosion(message: String) extends RuntimeException | |
object Bomb { | |
def tick(countdown: Int): Int = { | |
println("hello") | |
if (countdown == 0) throw new Explosion("BOOOOM!") | |
else tick(countdown - 1) | |
} | |
} | |
test("recursion") { | |
Bomb tick(3) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
import scala.annotation.tailrec