Skip to content

Instantly share code, notes, and snippets.

@cgopalan
Created September 13, 2011 04:04
Show Gist options
  • Save cgopalan/1213093 to your computer and use it in GitHub Desktop.
Save cgopalan/1213093 to your computer and use it in GitHub Desktop.
Scala product
object HigherOrderFunctions {
def product(f: Int => Int)(a: Int, b:Int): Int = {
if (a > b) 1 else f(a) * product(f)(a + 1, b)
}
def main(args: Array[String]) {
println("Product of range of numbers from 3 to 8 is: " + product(x => x)(3,8))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment