-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Specify short-circuiting behavior and add tests or laws #3355
Comments
I'll try attempt this. |
Not related to the collection short-circuiting behavior, but would it make sense to implement import scala.concurrent.{Await, Future}
import scala.concurrent.ExecutionContext.Implicits.global
import cats.implicits._
import concurrent.duration._
val f: Int => Future[Int] = i => {
print(s"$i ")
if (i >= 0) Future.successful(i) else Future.failed(new RuntimeException("not positive"))
}
@ Await.ready(List(-1, 1, 2, 3).traverse(f), 5.second)
-1 1 2 3 res0: Future[List[Int]] = Future(Failure(java.lang.RuntimeException: not positive)) |
@montrivo
I tried a
But then again it costs parallelisation, this implementation defers running f on each successive A until the previous result is available. The original
We should not defer from something that is taken as granted or assumed to hold, but then again we have |
There's currently some inconsistency between our collection instances with respect to where short-circuiting happens. To take a couple of examples:
…or:
Some specific cases of this are tracked in #3327 and fixed in #3328, but even after those changes we don't have tests to make sure we don't introduce more inconsistency, and we don't do a very good job of communicating to users what they can expect.
The text was updated successfully, but these errors were encountered: