Skip to content

Instantly share code, notes, and snippets.

@michalkowol
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save michalkowol/21b648b8a1fae1da8123 to your computer and use it in GitHub Desktop.

Select an option

Save michalkowol/21b648b8a1fae1da8123 to your computer and use it in GitHub Desktop.
import scala.concurrent.{Await, Future}
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
def ageNextYear(currentAge: Int): Future[Int] = {
Future { currentAge + 1 }
}
def welcome(name: String, age: Int): Future[String] = {
Future { s"$name $age" }
}
val f = for {
age <- ageNextYear(25)
message <- welcome("Michal", age)
} yield s"$message nextYear: $age"
Await.result(f, 1.second) // Michal 26 nextYear: 26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment