This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import scala.concurrent.{ExecutionContext, Future} | |
| import scala.util.{Failure, Success, Try} | |
| object FutureHelper { | |
| def partition[T](futures: List[Future[T]])(implicit executor: ExecutionContext): (Future[List[T]], Future[List[Throwable]]) = { | |
| val futuresOfTry: List[Future[Try[T]]] = futures.map(_.transform(Success(_))) | |
| val successes = Future.sequence(futuresOfTry) | |
| .map(_.collect { case Success(x) => x }) | |
| val failures = Future.sequence(futuresOfTry) |