Skip to content

Instantly share code, notes, and snippets.

@theboreddev
Last active October 26, 2021 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theboreddev/db4dd066cc20401e67ad1b9970096655 to your computer and use it in GitHub Desktop.
Save theboreddev/db4dd066cc20401e67ad1b9970096655 to your computer and use it in GitHub Desktop.
using either
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()
else -> HttpFailureProblem("Http call failed with status ${response.status} due to ${response.bodyString()}").left()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment