Created
June 16, 2019 14:55
-
-
Save Adzz/a096d85ae02a9ebd2be86754049b3aca to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Add do | |
def calculate(a, b) | |
end | |
# Now we can define implementations of it for the various kinds of | |
# data types we might get inside our collections that we are zipping. | |
defimpl Add, for: Integer do | |
def calculate(a, b) when is_integer(b), do: a + b | |
end | |
defimpl Add, for: Decimal do | |
def calculate(decimal, decimal_2 = %Decimal{}), do: Decimal.add(decimal, decimal_2) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment