Skip to content

Instantly share code, notes, and snippets.

@Adzz
Last active May 30, 2018 16:07
Show Gist options
  • Save Adzz/5480d1bef39f2f2fb0e61e96b6ae302f to your computer and use it in GitHub Desktop.
Save Adzz/5480d1bef39f2f2fb0e61e96b6ae302f to your computer and use it in GitHub Desktop.
defprotocol Perimeter do
def calculate(shape)
end
defimpl Perimeter, for: Square do
def calculate(square) do
square.side * 4
end
end
defimpl Perimeter, for: Circle do
def calculate(circle)
circle.radius * 2 * 3.14
end
end
Perimeter.calculate(%Circle{radius: 10})
Perimeter.calculate(%Square{side: 10})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment