carpenter carpenter - 2 months ago 16
Scala Question

Complex future unwraping

I know I can unwrap

Future[Future[Seq]] => Future[Seq]


With flatMap function

But how do I get following mapping?

Future[Seq[Future[Seq]]] => Future[Seq[Seq]]

Answer

Future.sequence will change a Seq[Future[...]] to a Future[Seq[...]]

So, something like this: obj.flatMap(x => Future.sequence(x)) perhaps?