summaryrefslogtreecommitdiff
path: root/src/code/2/my_red.exs
diff options
context:
space:
mode:
Diffstat (limited to 'src/code/2/my_red.exs')
-rw-r--r--src/code/2/my_red.exs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/code/2/my_red.exs b/src/code/2/my_red.exs
new file mode 100644
index 0000000..6966f3e
--- /dev/null
+++ b/src/code/2/my_red.exs
@@ -0,0 +1,10 @@
+defmodule MyReduce do
+ def reduce([], acc, _), do: acc
+ def reduce([h|t], acc, f) do
+ reduce(t, f.(h, acc), f)
+ end
+end
+
+[1, 2, 3, 4, 5] |>
+MyReduce.reduce(0, fn(x, acc) -> x + acc end)
+|> IO.inspect