Skip to content

Instantly share code, notes, and snippets.

@Adzz
Created June 16, 2019 15:11
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 Adzz/139bb622029e5ad5d7a199d9cb95794e to your computer and use it in GitHub Desktop.
Save Adzz/139bb622029e5ad5d7a199d9cb95794e to your computer and use it in GitHub Desktop.
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