I know that a Future.sequence
call can convert a List[Future[T]]
to a Future[List[T]]
, but what if I want to go the other way around?
I want to convert a Future[List[T]]
into a List[Future[T]]
.
The reason why I want to do this is as follows:
I send a message to an actor which uses Slick 3 to query a database. The Slick query returns list: Future[List[T]]
. If I could convert this list
to list: List[Future[T]]
, then I would be able to do:
list.map(convertToMessage).foreach(m => m pipeTo sender())
So basically I want to convert each record extracted from the DB into a message and then send it to a calling actor.
I don't think this is possible, sorry.
A Future[List[T]]
could complete with an empty list, a list with one element, or any number of elements.
So if you converted it to a List[Future[T]]
, how many Futures would the list contain?