Skip to content

Instantly share code, notes, and snippets.

@skie
Last active November 9, 2016 13:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skie/fdc773258ddd7c5a44e97be5445e0bb0 to your computer and use it in GitHub Desktop.
Save skie/fdc773258ddd7c5a44e97be5445e0bb0 to your computer and use it in GitHub Desktop.
defmodule T1 do
def t(arg) do
a = [
%{
fn: &f1/1,
res: :res1
}, %{
fn: &f2/1,
res: :res2
}, %{
res: :res3,
fn: &f3(&1, 2)
}
]
w_apply(a, arg)
end
defp w_apply([head|tail], arg) do
case (head.fn).(arg) do
true -> {:ok, head.res}
_ -> w_apply(tail, arg)
end
end
defp w_apply([], arg) do
{:err, arg}
end
defp f1(x) do
x == 1
end
defp f2(x) do
x == 2
end
defp f3(x, _y) do
x == 3
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment