summaryrefslogtreecommitdiff
path: root/src/code/2/my_red.exs
blob: 6966f3e9b86d1a3340f259aac6814c44cff86da6 (plain)
1
2
3
4
5
6
7
8
9
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