Skip to content

Add a Future companion method like Future.sequence that return Successes only. #9295

Open
@scabug

Description

@scabug

Future.sequence is failing when one of the Future is failed.
This is very useful but sometimes you want to ignore the failed futures and just get the list of successful futures.

The method to filter the successes only can be easily written :

 def sequenceSuccess[A, M[X] <: TraversableOnce[X]](in: M[Future[A]])(implicit cbf: CanBuildFrom[M[Future[A]], A, M[A]], executor: ExecutionContext) = {
  	in.foldLeft((Future.successful(cbf(in)))) {
      (fr, fa) =>
      (for (r <- fr; a <- fa) yield (r += a)) recoverWith {
      	case _ => fr
      }
    } map (_.result())
    }  

An extension of this feature would be another method that returns the following Tuple

(successes : Future[Seq[A]], failures : Future[Seq[Throwable]])

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions