Skip to content

Instantly share code, notes, and snippets.

View cblavier's full-sized avatar

Christian Blavier cblavier

View GitHub Profile
@cblavier
cblavier / facade.ex
Last active November 2, 2019 11:38
defmodule MyApp.Facade do
defmacro facade(mod) do
quote bind_quoted: [mod: mod] do
Enum.each apply(mod, :__info__, [:functions]), fn {fun, arity} ->
case arity do
0 -> defdelegate unquote(fun)(), to: mod
_ ->
values = Enum.map(1..arity, &(Macro.var(:"arg#{&1}", mod)))
defdelegate unquote(fun)(unquote_splicing(values)), to: mod