-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a Future companion method like Future.sequence that return Successes only. #9295
Comments
Imported From: https://issues.scala-lang.org/browse/SI-9295?orig=1 |
@viktorklang, is this something that has a chance to make it into the core standard library? We needed such a method for some production code yesterday and didn't find a good solution and in the end wrapped our results in an
and then This definitely interests some more people, see: I'd be willing to spend some time on this. |
I've seen this pop up a couple of times, so it's clear that there is some need for equivalent functionality. Not sure if something specialized such as .transform(t => Success(t.toOption)) Perhaps an alternative would be: final def sequenceSelectively[A, CC[X] <: IterableOnce[X], To](in: CC[scala.concurrent.Future[A]], predicate: Try[A] => Boolean)(implicit bf: scala.collection.BuildFrom[CC[scala.concurrent.Future[A]],A,To], implicit executor: scala.concurrent.ExecutionContext): scala.concurrent.Future[To] where final def sequenceSelectively[A, CC[X] <: IterableOnce[X], To](in: CC[scala.concurrent.Future[A]])(implicit bf: scala.collection.BuildFrom[CC[scala.concurrent.Future[A]],A,To], implicit executor: scala.concurrent.ExecutionContext): scala.concurrent.Future[To] = sequenceSelectively(in, {
case Success(_) => true
case Failure(t) => throw t
}) Haven't thought about it enough, but I'd rather create something more flexible, than special-casin g a use-case. |
That looks already much better. Thanks! I'd be fine with |
It's going to be a while before anything can be added to the standard library; see scala/scala-dev#661 |
@SethTisue, thanks for the info! Would I have to open a new PR in @viktorklang, please see scala/scala@fd23d4a for a first implementation. I'd be happy for any feedback! I tested using
|
I'm afraid we're not ready yet; scala/scala-collection-compat#328 and scala/scala-collection-compat#329 are still open/in-progress |
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 :
An extension of this feature would be another method that returns the following Tuple
The text was updated successfully, but these errors were encountered: