One of the great features of modern programming languages is structural pattern matching on algebraic data types. Once you’ve used this feature, you don’t ever want to program without it. You will find this in languages like Haskell and Scala. In Scala, algebraic types are provided by case classes. For example: sealed trait Tree case object Empty extends Tree case class Leaf(n: Int) extends Tree c
