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
val receiver: String = "Fructos" | |
val block: String.() -> Unit = { | |
println(toUpperCase()) | |
println(toLowerCase()) | |
println(capitalize()) | |
} | |
val result: Unit = with<String, Unit>(receiver, block) |
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, |
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), |
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.")) |
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 |
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
sealed class SafariBookAccess | |
data class Granted(val expirationDate: DateTime) : SafariBookAccess() | |
data class NotGranted(val error: AssertionError) : SafariBookAccess() | |
data class Blocked(val message: String) : SafariBookAccess() |
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
enum class Employee { | |
DEV_LEAD, | |
SENIOR_ENGINEER, | |
REGULAR_ENGINEER, | |
JUNIOR_ENGINEER | |
} | |
enum class Contract { | |
PROBATION, | |
PERMANENT, |
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
public final void sugar(@NotNull Response response) { | |
Intrinsics.checkParameterIsNotNull(response, "response"); | |
String var3; | |
if (response instanceof Success) { | |
var3 = ((Success)response).getBody(); | |
System.out.println(var3); | |
} else if (response instanceof Error) { | |
var3 = "" + ((Error)response).getCode() + ' ' + ((Error)response).getMessage(); | |
System.out.println(var3); |
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 sugar(response: Response) = when (response) { | |
is Success -> println(response.body) | |
is Error -> println("${response.code} ${response.message}") | |
Timeout -> println(response.javaClass.simpleName) | |
} |
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 sugar(response: Response) = when (response) { | |
is Success -> ... | |
is Error -> ... | |
Timeout -> ... | |
} |