Created
March 19, 2015 08:49
-
-
Save lucamolteni/ffb070303f320f2e4546 to your computer and use it in GitHub Desktop.
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
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