Last active
May 30, 2018 16:26
-
-
Save Adzz/38b7629d07b8d519b5896be550a55022 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
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