Skip to content

Instantly share code, notes, and snippets.

@Clokze
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save Clokze/43d93d2ae00b78454170 to your computer and use it in GitHub Desktop.

Select an option

Save Clokze/43d93d2ae00b78454170 to your computer and use it in GitHub Desktop.
elixir reduce
defmodule Math do
def sum_list([head|tail], accumulator) do
sum_list(tail, head + accumulator)
end
def sum_list([], accumulator) do
accumulator
end
end
IO.puts Math.sum_list([1, 2, 3], 0) #=> 6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment