Slide 20
Slide 20 text
Compile time check
https://goo.gl/NSXJEA
fun access(contract: Contract, employee: Employee) = when (Pair(contract, employee)) {
Pair(PROBATION, SENIOR_ENGINEER),
Pair(PROBATION, REGULAR_ENGINEER),
Pair(PROBATION, JUNIOR_ENGINEER) -> NotGranted(AssertionError("Not allowed for probation.”))
Pair(PERMANENT, SENIOR_ENGINEER),
Pair(PERMANENT, REGULAR_ENGINEER),
Pair(PERMANENT, JUNIOR_ENGINEER),
Pair(CONTRACTOR, SENIOR_ENGINEER) -> Granted(DateTime(1))
Pair(CONTRACTOR, REGULAR_ENGINEER),
Pair(CONTRACTOR, JUNIOR_ENGINEER) -> Blocked("Access for junior contractors is blocked.")
else -> throw AssertionError("Unsupported case of $employee and $contract")
}