Q:

Play framework Scala project: add ints to a Seq and return it

How is it possible to iterate over a Future[Seq[]] and add Int values to a Seq and return this Seq?
My code looks like this:
def createCopyOfProcessTemplate(processTemplateId: Int): Action[AnyContent] = Action.async {
processTemplateDTO.createCopyOfProcessTemplate(processTemplateId).map { process =>
  processTemplateDTO.getProcessStepTemplates(processTemplateId).map { steps =>
    steps.foreach(processStep =>
      processTemplateDTO.createCopyOfStepTemplates(processTemplateId, process.get.id.get, processStep))
  }

  // Fetch all Steps which belongs to this Template
  val processSteps: Future[Seq[ProcessStepTemplatesModel]] = processTemplateDTO.getProcessStepTemplates(processTemplateId)

  val stepIds:Seq[Int]=Seq()

  processSteps.map(
    steps => steps.foreach(
      step => stepIds:+step.id
    )
  )

  Ok(Json.obj("process" -> process, "steps" -> stepIds))
}
}

Because of asynchronicity, I think, the Seq is empty. How can I solve this?

A:

You could take a different approach:
Action.async {
  ...
  processSteps.map(_.map(_.id))
              .map(ids => Ok(Json.obj("process" -> process, "steps" -> ids)))
}

