Skip to content

Instantly share code, notes, and snippets.

@lucamolteni
Created March 19, 2015 08:49
Show Gist options
  • Save lucamolteni/ffb070303f320f2e4546 to your computer and use it in GitHub Desktop.
Save lucamolteni/ffb070303f320f2e4546 to your computer and use it in GitHub Desktop.
case class User(name: String, homepageUrl: Option[String])
case class UserProfile(userName: String, profile: String)
def findUser = Future.successful(User("Bob", Some("http://bob.com")))
def downloadProfile(url: String): Future[String] = Future.successful("Profile from the interwebs...")
def profile(user: User): Future[Iterable[String]] = Future.sequence(user.homepageUrl.map(downloadProfile))
def userProfile(userName: String): Future[Iterable[UserProfile]] =
findUser.flatMap(profile).map(_.map(UserProfile(userName, _)))
val profileFuture = userProfile("bob")
val res = Await.result(profileFuture, 1.second)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment