Created
September 13, 2021 01:01
-
-
Save ityonemo/d7e0c3344768f1858cc85d21ec02b42c to your computer and use it in GitHub Desktop.
protocol thingy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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