Question : sum type scala
Answered by : samuel-sayag
sum type is generally (2.x) encoded as a:
sealed trait ProductType
object ProductType { case object Element1 extends ProductType case class Element2(field1: Type1) extends ProductType ... case class ElementN(field1: Type1) extends ProductType
}
- "sealed" -> protect against wild extension
- case in object for code organisation
Source : | Last Update : Fri, 04 Jun 21