Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active February 3, 2026 20:23
Show Gist options
  • Select an option

  • Save dacr/9ccd09a197395a51f84d415eb0e60833 to your computer and use it in GitHub Desktop.

Select an option

Save dacr/9ccd09a197395a51f84d415eb0e60833 to your computer and use it in GitHub Desktop.
scala algebric data types / published by https://github.com/dacr/code-examples-manager #991c877f-0b43-4cab-86be-4a064660407e/1abcf1e32577faee390ef73a62611f729bf017ac
// summary : scala algebric data types
// keywords : scala, adt, algebric-data-types, language-feature, @testable
// publish : gist
// authors : David Crosson
// license : Apache License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt)
// id : 991c877f-0b43-4cab-86be-4a064660407e
// created-on : 2020-05-31T19:54:52Z
// managed-by : https://github.com/dacr/code-examples-manager
// run-with : scala-cli $file
// ---------------------
//> using scala "3.4.2"
//> using dep "org.scalatest::scalatest:3.2.10"
// ---------------------
// written after [John De Goes - 12 Steps To Better Scala (Part I)](https://youtu.be/71yhnTGw0hY)
println(
"""
|Algebric Data Types (ATD) is made of
| + Product types (just simple case class)
| - Defines commonality
| + Sum types
|
|the goal of ADT is to made impossible to represent an illegal state !
|
|[John De Goes - 12 Steps To Better Scala (Part I)](https://youtu.be/71yhnTGw0hY)
|
|""".stripMargin
)
// ----------------------------------------------------------------
// Products
case class Person(name:String, age:Int)
// ----------------------------------------------------------------
// Sums
sealed trait Contact
case class Email(value: String) extends Contact
case class Phone(value: String) extends Contact
println("so inheritance is not used...")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment