diff options
Diffstat (limited to 'Scala')
-rw-r--r-- | Scala/sandbox/curry.scala | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Scala/sandbox/curry.scala b/Scala/sandbox/curry.scala index 84b00ee..5c5577a 100644 --- a/Scala/sandbox/curry.scala +++ b/Scala/sandbox/curry.scala @@ -22,12 +22,21 @@ object Curry { def sumInts = sumCurry(x => x) def sumCubes = sumCurry(x => x * x * x) + // syntax shortcut + def sumCurryShort(f: Int => Int)(a: Int, b: Int): Int = + if (a > b) 0 else f(a) + sumCurryShort(f)(a + 1, b) + + // add _ if you want to treat it as a partially applied function + def sumCubesShort = sumCurryShort(cube)_ + def run = { println("Curry") println(sum(x => x * x, 3, 5)) - println(sumCurry(cube)(3, 5)) println(sumInts(3, 5)) + println(sumCurry(cube)(3, 5)) println(sumCubes(3, 5)) + println(sumCurryShort(cube)(3, 5)) + println(sumCubesShort(3, 5)) } } |