Sum Type Scala

[Solved] Sum Type Scala | Scala - Code Explorer | yomemimo.com
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

Answers related to sum type scala

Code Explorer Popular Question For Scala