Last active
August 29, 2015 14:10
-
-
Save michalkowol/21b648b8a1fae1da8123 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
| 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