Skip to content

Instantly share code, notes, and snippets.

@bmarcot
Last active December 15, 2015 12:59
Show Gist options
  • Save bmarcot/5263953 to your computer and use it in GitHub Desktop.
Save bmarcot/5263953 to your computer and use it in GitHub Desktop.
Scala By Example
import scala.annotation.tailrec
def sum(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