cats-effect
cats-effect copied to clipboard
Add instances for `EitherT` with consistent error type
Fixes https://github.com/typelevel/cats-effect/issues/2983 ... but breaks the laws 😕
For example this law is broken:
def fiberErrorIsOutcomeErrored(e: E) =
F.start(F.raiseError[Unit](e)).flatMap(_.join) <-> F.pure(Outcome.Errored(e))
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)))
}
}
unfixable:
- https://github.com/typelevel/cats/issues/4308