summaryrefslogtreecommitdiffstats
path: root/Scala/sandbox/sum.scala
diff options
context:
space:
mode:
Diffstat (limited to 'Scala/sandbox/sum.scala')
-rw-r--r--Scala/sandbox/sum.scala14
1 files changed, 14 insertions, 0 deletions
diff --git a/Scala/sandbox/sum.scala b/Scala/sandbox/sum.scala
new file mode 100644
index 0000000..a09f26b
--- /dev/null
+++ b/Scala/sandbox/sum.scala
@@ -0,0 +1,14 @@
+
+object Sum {
+
+ def sum (f: Int => Int, a: Int, b: Int) = {
+ def loop(a: Int, acc: Int): Int =
+ if (a > b) acc
+ else loop(a + 1, f(a) + acc)
+ loop(a, 0)
+ }
+
+ def run =
+ println(sum(x => x * x, 3, 5))
+
+}