Reputation: 330
I'm trying to await on a funky structure like this: Future[List[Future[List[Object]]]]
. Await only gets rid of the outer most Future, is there a clean way of trimming this down to a simple List[Object]
?
Upvotes: 2
Views: 991
Reputation: 53819
Using Future.sequence
:
val original: Future[List[Future[List[Object]]]] = // ...
val futureList =
original.flatMap(l => Future.sequence(l)) // Future[List[List[Object]]]
.map(_.flatten) // Future[List[Object]]
Upvotes: 9