Skip to content

Instantly share code, notes, and snippets.

@samstarling
Created March 13, 2015 15:11
Show Gist options
  • Save samstarling/3628274f3d14262307ee to your computer and use it in GitHub Desktop.
Save samstarling/3628274f3d14262307ee to your computer and use it in GitHub Desktop.
package com.samstarling.futures
import com.twitter.util.Future
object SequentialComposition extends App {
case class User(name: String)
def authenticate(credentials: String) = Future { Some(User("sam")) }
def getTweets(user: User) = Future { List("1", "2", "3") }
val future = for {
user <- authenticate("foo")
tweets <- getTweets(user)
} yield (user, tweets)
future onSuccess { case (user, tweets) =>
println(s"The tweets for $user are: $tweets")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment