exjpet v0.1.0 Exjpet.Delegate

Exjpet.Delegate inject functions delegation to the target module, for all exported functions of that module.

Example

The following module proxies Erlang :maps module. For illustration purpose it also exports a foo function.

iex> defmodule MyMap do
...>   use Exjpet.Delegate, to: :maps
...>   def foo do
...>     :foo
...>   end
...> end
iex> MyMap.get(:a, %{a: 42})
42
iex> MyMap.to_list(%{a: 42, b: "foo"})
[a: 42, b: "foo"]
iex> MyMap.foo
:foo

Aliasing

Using alias as target module is not supported.

Following declaration will compile

defmodule DelegateToList do
  use Exjpet.Delegate, List # ok
end

But that one won’t

defmodule FailedDelegateToList do
  alias List, as: MyList
  use Exjpet.Delegate, MyList # failed !
end