Last active
November 9, 2016 13:10
-
-
Save skie/fdc773258ddd7c5a44e97be5445e0bb0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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