https://kotlinlang.org logo
Title
p

poohbar

08/03/2018, 6:25 PM
Is there anyway I could get:
CompletableFuture<List<Person>>
from
List<CompletableFuture<Person>>
I can't wrap my head around it 😕
:stackoverflow: 1
r

Ruckus

08/03/2018, 6:37 PM
According to 😒tackoverflow: (https://stackoverflow.com/questions/30025428/listfuture-to-futurelist-sequence), you can use a function like this:
fun <T> List<CompletableFuture<T>>.unwrap(): CompletableFuture<List<T>> =
    CompletableFuture.allOf(*toTypedArray()).thenApply { map { it.join() } }
Basically, it creates a wrapper
CompletableFuture
that waits for all the others to finish, then unwraps each value into a list.
p

poohbar

08/03/2018, 6:53 PM
interesting.. thank you, hopefully the dispatcher will be happy with this
👍 1
d

diesieben07

08/03/2018, 7:22 PM
holds up "Monads" flag
k

karelpeeters

08/03/2018, 7:23 PM
Cries while attempting to learn monads
c

Can Orhan

08/06/2018, 7:08 AM
Cries over the memory of skipping over the monads question in my university exam