Reputation: 33544
In scala you can "map" collection of futures to future of collection like that:
val l: List[Future[String]] = List(Future {"1"}, Future {"2"})
val x: Future[List[String]] = Future.sequence(l)
How to same thing but with kotlin?
Upvotes: 1
Views: 416
Reputation: 33769
Assuming you use coroutines:
val l: List<Deferred<String>> = (1..2).map {i -> async(Unconfined){ "$i" }}
val x: Deffered<List<String>> = async(Unconfined) { l.map {it.await()} }
Upvotes: 5