Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SCALA

sum type scala

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
 
PREVIOUS NEXT
Tagged: #sum #type #scala
ADD COMMENT
Topic
Name
4+1 =