Skip to content

Instantly share code, notes, and snippets.

@Adzz
Last active May 30, 2018 16:26
Show Gist options
  • Save Adzz/38b7629d07b8d519b5896be550a55022 to your computer and use it in GitHub Desktop.
Save Adzz/38b7629d07b8d519b5896be550a55022 to your computer and use it in GitHub Desktop.
defmodule Perimeter do
def calculate(shape) do
case shape do
%Square{side: side} -> side * 4
%Circle{radius: radius} -> radius * 2 * 3.14
end
end
end
Perimeter.calculate(%Square{side: 10}) #=> 40
Perimeter.calculate(%Circle{radius: 10}) #=> 62.8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment