Without Future, that's how I combine all smaller Seq into one big Seq with a flatmap
category.getCategoryUrlKey(id: Int):Seq[Meta] // main method
val appDomains: Seq[Int]
val categories:Seq[Meta] = appDomains.flatMap(category.getCategoryUrlKey(_))
Now the method getCategoryUrlKey
could fail. I put a circuit breaker in front to avoid to call it for the next elements after an amount of maxFailures. Now the circuit breaker doesn't return a Seq
but a Future[Seq]
lazy val breaker = new akka.pattern.CircuitBreaker(...)
private def getMeta(appDomainId: Int): Future[Seq[Meta]] = {
breaker.withCircuitBreaker {
category.getCategoryUrlKey(appDomainId)
}
}
How to iterate through the List appDomains
and combine the result into one single Future[Seq] , possible into Seq ?
If Functional Programming is applicable, is there a way to directly transform without temporary variables ?
squashFutures
. Is there a way to directly transform without temporary variables ? – Antisepsis