Skip to content

Instantly share code, notes, and snippets.

@falood
Last active December 28, 2015 18:39
Show Gist options
  • Save falood/7545069 to your computer and use it in GitHub Desktop.
Save falood/7545069 to your computer and use it in GitHub Desktop.
merge two Module's function
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