Created
June 16, 2019 15:11
-
-
Save Adzz/139bb622029e5ad5d7a199d9cb95794e 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 Subtract do | |
def calculate(a, b) | |
end | |
# And implement it | |
defimpl Subtract, for: Integer do | |
def calculate(a, b) when is_integer(b), do: a - b | |
end | |
defimpl Subtract, for: Decimal do | |
def calculate(a, b = %Decimal{}), do: Decimal.sub(a, b) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment