-
-
Save theboreddev/287d9976c25f05b2294ddff61d6d8c3a to your computer and use it in GitHub Desktop.
Using Nullable type
This file contains 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 findEmployeeByName(name: String): Either<Problem, Employee?> { | |
val request = Request(Method.GET, "http://myservice.org/employees").query("name", name) | |
val response = client(request) | |
return when (response.status) { | |
Status.OK -> Employee(response.bodyString()).right() | |
Status.NOT_FOUND -> Either.Right<Employee?>(null) | |
else -> HttpFailureProblem("Http call failed due to ${response.bodyString()}").left() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment