Last active
December 28, 2015 18:39
-
-
Save falood/7545069 to your computer and use it in GitHub Desktop.
merge two Module's function
This file contains hidden or 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 M1 do | |
def fun(:arg1) do | |
IO.puts "arg1" | |
end | |
end | |
defmodule M2 do | |
def fun(:arg2) do | |
IO.puts "arg2" | |
end | |
end | |
defmodule M3 do | |
def tryfun([], _), do: "not found" | |
def tryfun([{m, f}|t], a) do | |
try do | |
apply m, f, a | |
rescue | |
[FunctionClauseError] -> | |
tryfun(t, a) | |
end | |
end | |
def go(x) do | |
fm_list = [{M1, :fun}, {M2, :fun}] | |
tryfun(fm_list, [x]) | |
end | |
end% |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment