Created
October 5, 2016 11:13
-
-
Save ashic/52178f0e10b46e429b115e2aa478b441 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
| def foo(a: Future[Int], b: Future[String]) : Future[MyThing] = | |
| for { | |
| x <- a | |
| y <- b | |
| } yield MyThing(a, b) | |
| def foo2(a: Future[Int], b: Future[String]) : Future[MyThing] = | |
| a.flatmap(x => b.map(y => MyThing(x, y))) | |
| def foo3(a: Option[Int], b: Option[String]) : Option[MyThing] = | |
| for { | |
| x <- a | |
| y <- b | |
| } yield MyThing(a, b) | |
| def foo4(a: Option[Int], b: Option[String]) : Option[MyThing] = | |
| a.flatmap(x => b.map(y => MyThing(x, y))) | |
| //usage: | |
| val res = Await.result(foo(Future(23), Future("blah")), 2 seconds) | |
| val res2 = foo3(Some(23), Some("blah")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment