Created
November 10, 2017 20:59
-
-
Save JorgeCastilloPrz/2ae1ba640aec4486207dd5f9bf6c8465 to your computer and use it in GitHub Desktop.
gist for blog snippet
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 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