I am using twitter finagle
framework and given a sequence of future of optionals I would like to filter them based on the state of the option.
seqFuture : Seq[Future[Option[Foo]]]
val filteredFuture = seqFuture map { fut => fut map {
opt => if(opt.isDefined) bar(opt.get)
}
}
The function bar : Foo => Bar
could be identity, but I do not want to return an Option[Bar]
. If the option is not defined I want the future to silently fail and only chain further processing on the futures that contain a defined option.
I have tried a combination of flatten, flatMap, match case Some(_) =>
, but I do not arrive at filtering them. If I throw an Exception
where the option is not defined all of the futures processing will fail (since I collect them at some point)
I could not find any solution to this problem in finagle guide
Alternative solutions to filter and chaining futures using the finagle framework would still be appreciated.