Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Future[Seq[Person]] instead of Seq[Future[Person]]

Tags:

scala

future

I have two external call which

  1. Which gives Future[Seq[People]]
  2. Which takes person_id and returns person_status as Future[String]

I need to update each person status using second call from the sequence available in first call. This is how I tried,

getFuturePeople.map( (seqPeople : Seq[People]) => {
     seqPeople.map(person => getStatus(person._id).status).map(status => {
     //Update status for this person but I get Seq[Future[Peoson]]
   }) 
})
like image 785
Puneeth Reddy V Avatar asked Jul 31 '18 05:07

Puneeth Reddy V


1 Answers

Use can use Future.sequence to transform the result, eg:

val futureOfSeq = Future.sequence(seqOfFuture)

like image 143
Ryan Avatar answered Nov 15 '22 09:11

Ryan