That question may be a dumb one where any search engine should give me a quick answer. However I did not find anything, so I may use the wrong terms.
If F# one can do an exclusive (OR) composition with the |
symbol :
type LeftOrRightOrNone =
| Left of string
| Right of string
| None
Which mean that a LeftOrRightOrNone
can only be of type Left
OR Right
OR None
.
We can have the same constraint with a sealed trait:
sealed trait LeftOrRightOrNone
case class Left(..) extends LeftOrRightOrNone
case class Right(..) extends LeftOrRightOrNone
case object None extends LeftOrRightOrNone
But I wonder if there is a simpler way to declare such types in Scala ?
Thanks