Skip to content

Instantly share code, notes, and snippets.

@JorgeCastilloPrz
Created November 10, 2017 20:59
Show Gist options
  • Save JorgeCastilloPrz/2ae1ba640aec4486207dd5f9bf6c8465 to your computer and use it in GitHub Desktop.
Save JorgeCastilloPrz/2ae1ba640aec4486207dd5f9bf6c8465 to your computer and use it in GitHub Desktop.
gist for blog snippet
fun getCountryCode(maybePerson : Either<BizError, Person>): Either<BizError, String> =
Either.monadError<BizError>().binding {
val person = maybePerson.bind()
val address = person.address.toEither({ AddressNotFound(person.id) }).bind()
val country = address.country.toEither({ CountryNotFound(address.id) }).bind()
yields(country.code)
}.ev()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment