Giter VIP home page Giter VIP logo

Comments (9)

neko-kai avatar neko-kai commented on August 23, 2024

@larousso The errors are already accumulated in Cause[E] for ZIO. Could you please check if

(io1, io2).parTupled.mapErrorCause { 
  c => Cause.fail(NonEmptyList.fromListUnsafe(c.failures).reduce)
}

contains all the errors you're looking for?

from interop-cats.

larousso avatar larousso commented on August 23, 2024

Yes, this is working :

testM("zio") {
  import cats.implicits._
  import zio.interop.catz._
  assertM(
    (ZIO.fail(NonEmptyList.one("Error1")), ZIO.fail(NonEmptyList.one("Error2"))).parTupled.mapErrorCause { c =>
      Cause.fail(NonEmptyList.fromListUnsafe(c.failures).reduce)
    }.either,
    isLeft(
      equalTo(NonEmptyList.of("Error1", "Error2"))
    )
  )
}

from interop-cats.

neko-kai avatar neko-kai commented on August 23, 2024

@larousso In that case I think this issue can be closed? I feel like there wouldn't be much gain from a new Parallel instance with E: Semigroup constraint since Cause already does the accumulation here....

from interop-cats.

larousso avatar larousso commented on August 23, 2024

I really prefer the concise syntax with just

(io1, io2).parTupled

instead of

(io1, io2).parTupled.mapErrorCause { 
  c => Cause.fail(NonEmptyList.fromListUnsafe(c.failures).reduce)
}

but I understand that it's not fine for you to add a new instance with a E as a monoid so I can close the issue.

from interop-cats.

neko-kai avatar neko-kai commented on August 23, 2024

@larousso you can add it and there's a precedent with MonoidK/SemigroupK instances - https://github.com/zio/interop-cats/blob/master/interop-cats/shared/src/main/scala/zio/interop/cats.scala#L109 - but then I'm not sure how intuitive it would be to change the error behavior based on existence/nonexistence of instances for error (the same applies to the SemigroupK instance)

from interop-cats.

larousso avatar larousso commented on August 23, 2024

It seams to be the standard behavior for cats.
For exemple:

        testM("cats") {
          import cats._
          import cats.data._
          import cats.implicits._
          import zio.interop.catz._

          val et1 = EitherT.leftT[Task, String](NonEmptyList.one("Error1"))
          val et2 = EitherT.leftT[Task, String](NonEmptyList.one("Error2"))

          assertM(
            (et1, et2).parTupled.value,
            isLeft(
              equalTo(NonEmptyList.of("Error1", "Error2"))
            )
          )
        }

from interop-cats.

neko-kai avatar neko-kai commented on August 23, 2024

@larousso The difference is that you must specifically wrap your IO in EitherT to enable this behavior. There's no low-priority instance for Parallel[EitherT[...]] that doesn't require a Semigroup instance – therefore your errors will either be accumulated or your compilation will fail, there won't be a silent change of behavior towards non-accumulation from a missing instance.

from interop-cats.

neko-kai avatar neko-kai commented on August 23, 2024

For ZIO there's a silent change of behavior in SemigroupK currently. I'm not super fond of that as is, with a conditional Parallel instance there will be more silent changes of behavior...

/cc @zio/core for opinions...

from interop-cats.

jdegoes avatar jdegoes commented on August 23, 2024

ZIO cannot guarantee parallel error accumulation. This is because when one running effect fails, the others are canceled immediately... possibly before they begin.

You could do:

ZIO.uninterruptible {
  ...
}

If you wanted to "force" non-cancellation. That should allow you to get parallel error accumulation.

from interop-cats.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.