Last active
December 2, 2017 21:26
-
-
Save sliskiCode/79e9088bd0d0e2636048a2908b71fde8 to your computer and use it in GitHub Desktop.
6 magic sugars that can make your Kotlin codebase happier #11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun access(contract: Contract, | |
employee: Employee) = when (contract to employee) { | |
PROBATION to SENIOR_ENGINEER, | |
PROBATION to REGULAR_ENGINEER -> NotGranted(AssertionError("Access not allowed on probation contract.")) | |
PERMANENT to SENIOR_ENGINEER, | |
PERMANENT to REGULAR_ENGINEER, | |
PERMANENT to JUNIOR_ENGINEER, | |
CONTRACTOR to SENIOR_ENGINEER -> Granted(DateTime(1)) | |
CONTRACTOR to REGULAR_ENGINEER, | |
PROBATION to JUNIOR_ENGINEER, | |
CONTRACTOR to JUNIOR_ENGINEER -> Blocked("Access for junior contractors is blocked.") | |
else -> throw AssertionError("Unsupported case of $employee and $contract") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment