diff options
-rw-r--r-- | Scala/sandbox/curry.scala | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/Scala/sandbox/curry.scala b/Scala/sandbox/curry.scala index 5c5577a..1a2e44c 100644 --- a/Scala/sandbox/curry.scala +++ b/Scala/sandbox/curry.scala @@ -29,6 +29,12 @@ object Curry { // add _ if you want to treat it as a partially applied function def sumCubesShort = sumCurryShort(cube)_ + // product + def product(f: Int => Int)(a: Int, b: Int): Int = + if (a > b) 1 else f(a) * product(f)(a + 1, b) + + def fact(n: Int) = product(x => x)(1, n) + def run = { println("Curry") println(sum(x => x * x, 3, 5)) @@ -37,6 +43,8 @@ object Curry { println(sumCubes(3, 5)) println(sumCurryShort(cube)(3, 5)) println(sumCubesShort(3, 5)) + println(product(x => x * x)(3, 4)) + println(fact(4)) } } |