Skip to content

Instantly share code, notes, and snippets.

@ashic
Created October 5, 2016 11:13
Show Gist options
  • Select an option

  • Save ashic/52178f0e10b46e429b115e2aa478b441 to your computer and use it in GitHub Desktop.

Select an option

Save ashic/52178f0e10b46e429b115e2aa478b441 to your computer and use it in GitHub Desktop.
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