Skip to content

Instantly share code, notes, and snippets.

@shiwork
Created May 26, 2015 09:01
Show Gist options
  • Save shiwork/af7ec21e475383050291 to your computer and use it in GitHub Desktop.
Save shiwork/af7ec21e475383050291 to your computer and use it in GitHub Desktop.
elixir
defmodule Math do
def sum_list([head|tail]) do
sum_list(tail, head)
end
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])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment