Skip to content

Instantly share code, notes, and snippets.

@ityonemo
Created September 13, 2021 01:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ityonemo/d7e0c3344768f1858cc85d21ec02b42c to your computer and use it in GitHub Desktop.
Save ityonemo/d7e0c3344768f1858cc85d21ec02b42c to your computer and use it in GitHub Desktop.
protocol thingy
defprotocol Proto do
def generic_getter(value)
end
defmodule A do
defstruct [:a]
def generic_getter(v), do: v.a
defimpl Proto do
defdelegate generic_getter(value), do: A
end
end
defmodule B do
defstruct [:b]
def generic_getter(v), do: v.b
defimpl Proto do
defdelegate generic_getter(value), to: B
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment