cats-effect icon indicating copy to clipboard operation
cats-effect copied to clipboard

Add instances for `EitherT` with consistent error type

Open armanbilge opened this issue 3 years ago • 2 comments

Fixes https://github.com/typelevel/cats-effect/issues/2983 ... but breaks the laws 😕

armanbilge avatar Jun 12 '22 22:06 armanbilge

For example this law is broken:

  def fiberErrorIsOutcomeErrored(e: E) =
    F.start(F.raiseError[Unit](e)).flatMap(_.join) <-> F.pure(Outcome.Errored(e))

armanbilge avatar Jun 12 '22 22:06 armanbilge

Ok, I was able to fix that law by overriding liftOutcome like so:

      override def liftOutcome[A](
          oc: Outcome[F, E, Either[E, A]]): F[Outcome[EitherT[F, E, *], E, A]] =
        oc match {
          case Outcome.Canceled() => F.pure(Outcome.Canceled())
          case Outcome.Errored(e) => F.pure(Outcome.Errored(e))
          case Outcome.Succeeded(foa) => foa.map {
            case Left(e) => Outcome.Errored(e)
            case Right(a) => Outcome.Succeeded(EitherT.right(F.pure(a)))
          }
        }

armanbilge avatar Jun 12 '22 23:06 armanbilge

unfixable:

  • https://github.com/typelevel/cats/issues/4308

armanbilge avatar Sep 25 '22 10:09 armanbilge