Skip to content

Instantly share code, notes, and snippets.

Created November 18, 2021 07:32
What would you like to do?
Using Nullable type
fun findEmployeeByName(name: String): Either<Problem, Employee?> {
val request = Request(Method.GET, "").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