Skip to content

Instantly share code, notes, and snippets.

@jcoyne
Created March 14, 2013 03:53
Show Gist options
  • Save jcoyne/5158691 to your computer and use it in GitHub Desktop.
Save jcoyne/5158691 to your computer and use it in GitHub Desktop.
I'm trying to write Ruby's inject method in Elixir.
defmodule Foo do
def bar(acc, [H | T]) do
acc + H + bar(T)
end
def bar(acc, []) do
acc
end
end
Foo.bar(7, [1, 2, 3])
** (FunctionClauseError) no function clause matching: Foo.bar(7, [1,2,3])
iex:110: Foo.bar(7, [1,2,3])
erl_eval.erl:569: :erl_eval.do_apply/6
src/elixir.erl:133: :elixir.eval_forms/3
/private/tmp/elixir-Zrrr/elixir-lang-elixir-90ff71b/lib/iex/lib/iex/server.ex:19: IEx.Server.do_loop/1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment