Skip to content

Instantly share code, notes, and snippets.

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