Skip to content

Instantly share code, notes, and snippets.

@j-thepac
Created December 15, 2021 16:57
Show Gist options
  • Save j-thepac/94f31e1cf276e5e37d3149e69e0de1c8 to your computer and use it in GitHub Desktop.
Save j-thepac/94f31e1cf276e5e37d3149e69e0de1c8 to your computer and use it in GitHub Desktop.
Scala Rules
// They’re an idiomatic way of representing data using “ands” and “ors”. For example:
// a shape is a rectangle or a circle
// a rectangle has a width and a height
// a circle has a radius
// In ADT (Algebraic Data Types (ADTs))terminology, “and” types such as rectangle and circle are products,
// whereas the “or” types such as shape are coproducts.
// In Scala, we typically represent products using case classes and coproducts using sealed traits:
sealed trait Shape
final case class Rectangle(width: Double, height: Double) extends Shape
final case class Circle(radius: Double) extends Shape
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment