Created
January 7, 2019 14:51
-
-
Save vvviiimmm/d59bb6cfd3496979eeca988e58d50386 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
// Scala doesn't have a nice syntax for sum types so | |
// it looks like a familiar OOP inheritance tree. | |
sealed trait Shape | |
// But don't get confused: the 'extends' here stands for 'is' | |
// relationship, not in a sense of 'extends and overrides methods'. | |
// It only says that when you create a Circle it will be of type 'Shape' | |
case class Circle(radius: Int) extends Shape | |
case class Square(side: Int) extends Shape |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment