package ed import concurrent.{Await, Future} import concurrent.duration.Duration import concurrent.ExecutionContext.Implicits.global // Pro Tip: you can print the code generated by the Scala compiler after the // translation of for-comprehensions by running: // // scala -Xprint:firstTransform src/main/scala/ed/40056.scala @main def futuresForTranslation = val f1 = Future { 451 } val f2 = Future { 1984 } val f3 = for v1 <- f1; v2 <- f2 yield v1 + v2 println(Await.result(f3, Duration.Inf)) val f4 = Future { 451 } val f5 = Future { 1984 } val f6 = f4.flatMap(v4 => f5.map(v5 => v4 + v5)) println(Await.result(f6, Duration.Inf))