📜  sum type scala - 任何代码示例

📅  最后修改于: 2022-03-11 14:59:11.949000             🧑  作者: Mango

代码示例1
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