Creating Elixir Protocol with defprotocol

Creating Elixir Protocol with defprotocol

Elixir has a very flexible feature called Protocols. These can be used for helper utilities modules.

defprotocol Double do
  def double(input)
end

defimpl Double, for: Integer do
  def double(int) do
    int * 2
  end
end

defimpl Double, for: List do
  def double(list) do
    list ++ list
  end
end

Hoping I can do more on how this can be used in a phoenix app.