Last active
December 2, 2017 08:33
-
-
Save sliskiCode/1aa6e774ee1f1a2cbfa18362d0e54ddb to your computer and use it in GitHub Desktop.
6 magic sugars that can make your Kotlin codebase happier #10
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 (Pair(contract, employee)) { | |
Pair(PROBATION, SENIOR_ENGINEER), | |
Pair(PROBATION, REGULAR_ENGINEER), | |
Pair(PROBATION, JUNIOR_ENGINEER) -> NotGranted(AssertionError("Access not allowed on probation contract.")) | |
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") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment