Imho it is: Why duplicate the delegate functionality if it’s not implementation dependant:
defmodule Handler do
def delegate(impl, args) do
case impl.handle(args) do
:ok ->
:ok
{:error, reason} = result ->
do_something(result)
:ok
end
end
defp do_something(_) do
# Log stuff or whatever
end
@callback handle(any) :: :ok | {:error, any}
@optional_callbacks handle: 1
end
defmodule Implementation do
@behaviour Handler
@impl true
def handle(_) do
:ok
end
end
defmodule OtherImplementation do
@behaviour Handler
@impl true
def handle(_) do
{:error, "something went wrong"}
end
end






















