Protocols enable polymorphism in Elixir. Define protocols with defprotocol:
defprotocol Log do
def log(value, opts)
end
Implement a protocol with defimpl:
require Logger
# User and Post are custom structs
defimpl Log, for: User do
def log(user, _opts) do
Logger.info "User: ...