Felix
Felix

Reputation: 5619

playframework scala how to flat a Future[Seq[Seq[Int]]

I have the following code:

val f0: Future[Seq[Seq[Int]]] = processPrerequisitesDTO.getProcessPrerequisiteIdsByProcessTemplateId(processTemplateId).flatMap(pres =>
  Future.sequence(
    pres.map(pre =>
      processPrerequisitesDTO.getProcessPrerequisiteProcessTemplateIdsByProcessTemplateId(pre)
    ))
)

How can I flat one Seq? The Future should be kept.

Thanks.

Upvotes: 0

Views: 75

Answers (1)

Jeffrey Chung
Jeffrey Chung

Reputation: 19517

You could call map on the Future and flatten the Seq[Seq[Int]]:

val flattened = f0.map(_.flatten)
// Future[Seq[Int]]

Upvotes: 1

Related Questions