Skip to content

Instantly share code, notes, and snippets.

@amirkarimi
Created January 3, 2018 22:00
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 amirkarimi/be1d18af79539b0bbab01f96439a48e6 to your computer and use it in GitHub Desktop.
Save amirkarimi/be1d18af79539b0bbab01f96439a48e6 to your computer and use it in GitHub Desktop.
def getUser(id: Int): Future[Either[String, User]] = ???
def getCity(user: User): Future[Either[String, City]] = ???
def getCountry(city: City): Future[Either[String, Country]] = ???
def getCountryByUserId(id: Int): Future[Either[String, Country]] = {
getUser(id) flatMap {
case Left(err) => Future.successful(Left(err))
case Right(user) =>
getCity(user) flatMap {
case Left(err) => Future.successful(Left(err))
case Right(city) => getCountry(city)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment