Last active
December 15, 2015 12:59
-
-
Save bmarcot/5263994 to your computer and use it in GitHub Desktop.
Scala By Example
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 scala.annotation.tailrec | |
def product(f: Int => Int)(a: Int, b: Int) : Int = { | |
@tailrec | |
def iter(a: Int, result: Int) : Int = { | |
if (a > b) result | |
else iter(a + 1, f(a) * result) | |
} | |
iter(a, 0) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment