Skip to content

Instantly share code, notes, and snippets.

@bmarcot
Last active December 15, 2015 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bmarcot/5263994 to your computer and use it in GitHub Desktop.
Save bmarcot/5263994 to your computer and use it in GitHub Desktop.
Scala By Example
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