Skip to content

Instantly share code, notes, and snippets.

@sliskiCode
Last active December 2, 2017 08:32
Show Gist options
  • Save sliskiCode/f6830982ce9ed65ba1049259b3e2fffe to your computer and use it in GitHub Desktop.
Save sliskiCode/f6830982ce9ed65ba1049259b3e2fffe to your computer and use it in GitHub Desktop.
6 magic sugars that can make your Kotlin codebase happier #9
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