Skip to content

Instantly share code, notes, and snippets.

@vvviiimmm
Created January 7, 2019 14:51
Show Gist options
  • Save vvviiimmm/d59bb6cfd3496979eeca988e58d50386 to your computer and use it in GitHub Desktop.
Save vvviiimmm/d59bb6cfd3496979eeca988e58d50386 to your computer and use it in GitHub Desktop.
// 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