Given an A
, which may have optional fields, a
and b
:
case class A(a: Option[Int], b: Option[String])
I could define A
as an Algebraic Data Type.
However, it would require 4 sub-classes to account for each None/Option
choice:
sealed trait AADT
case class Aa(a: Int) extends AADT
case class Aab(a: Int, b: String) extends AADT
case class Ab(b: String) extends AADT
case object Neither extends AADT
I'd argue that this ADT is preferable to the above A
option, which has Option
types.
However, this type could quickly get out of hand with 3, 4, etc. fields.
Is there a third way to implement A
, i.e. not using either my first or second implementation?