final case class OpenEnrollment( id: UUID, startDate: Instant, endDate: Instant, status: OpenEnrollmentState, productMappings: NonEmptyList[ProductMapping], eligibilityGroups: NonEmptyList[EligibilityGroup], employerId: String, createdByTitanUser: String) def createOpenEnrollment(...): ValidatedNel[OpenEnrollmentError, OpenEnrollment] def editOpenEnrollment(...): ValidatedNel[OpenEnrollmentError, OpenEnrollment] def deleteOpenEnrollment(...): ValidatedNel[OpenEnrollmentError, OpenEnrollment] def runOpenEnrollment(...): ValidatedNel[OpenEnrollmentError, OpenEnrollment] def finishRunningOpenEnrollment(...): ValidatedNel[OpenEnrollmentError, OpenEnrollment] def errorRunningOpenEnrollment(...): ValidatedNel[OpenEnrollmentError, OpenEnrollment]
"Make illegal states unrepresentable"
https://blogs.janestreet.com/effective-ml-revisited/
Traits!
trait OpenEnrollment { val id: UUID val startDate: Instant val endDate: Instant val status: OpenEnrollmentState val productMappings: NonEmptyList[ProductMapping] val eligibilityGroups: NonEmptyList[EligibilityGroup] val employerId: String val createdByTitanUser: String } object OpenEnrollment { private case class OpenEnrollmentImpl( id: UUID, startDate: Instant, endDate: Instant, status: OpenEnrollmentState, productMappings: NonEmptyList[ProductMapping], eligibilityGroups: NonEmptyList[EligibilityGroup], employerId: String, createdByTitanUser: String ) extends OpenEnrollment {} }
trait X { val a: Int val b: String } object X { private case class XImpl(a: Int, b: String) extends X {} def mkX(a: Int, b: String): X = XImpl(a, b) def editA(x: X, newA: Int): X = XImpl(newA, x.b) def unapply(x: XImpl): Option[(Int, String)] = Some((x.a, x.b)) }
unapply
method.