Skip to content

Instantly share code, notes, and snippets.

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