Last active
December 2, 2017 08:32
-
-
Save sliskiCode/f6830982ce9ed65ba1049259b3e2fffe to your computer and use it in GitHub Desktop.
6 magic sugars that can make your Kotlin codebase happier #9
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(employee: Employee, | |
contract: Contract): SafariBookAccess { | |
return when (employee) { | |
SENIOR_ENGINEER -> when (contract) { | |
PROBATION -> NotGranted(AssertionError("Access not allowed on probation contract.")) | |
PERMANENT -> Granted(DateTime()) | |
CONTRACTOR -> Granted(DateTime()) | |
} | |
REGULAR_ENGINEER -> when (contract) { | |
PROBATION -> NotGranted(AssertionError("Access not allowed on probation contract.")) | |
PERMANENT -> Granted(DateTime()) | |
CONTRACTOR -> Blocked("Access blocked for $contract.") | |
} | |
JUNIOR_ENGINEER -> when (contract) { | |
PROBATION -> NotGranted(AssertionError("Access not allowed on probation contract.")) | |
PERMANENT -> Blocked("Access blocked for $contract.") | |
CONTRACTOR -> Blocked("Access blocked for $contract.") | |
} | |
else -> throw AssertionError() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment