You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to stack a WriterT and EitherT together - ultimately something like IO[Writer[Log, Either[Throwable, A]]]. The idea is that even in the event of an error the log up to that point should be maintained.
I have created a POC which uses a transformer stack of EitherT[WriterT[IO, Log, *], Throwable, *] and when I materialise the program it works as expected. The logs are present even in the event of an error. However FunctorListen seems to short circuit in the event of an error. Here is the code itself:
objectPOCextendsIOApp {
importcats.instances.vector._importcats.mtl.implicits._importcats.syntax.flatMap._importcats.syntax.functor._typeLog=Vector[String]
overridedefrun(args: List[String]):IO[ExitCode] = {
valname= getName[EitherT[WriterT[IO, Log, *], Throwable, *]]
// this works even with a raised error so the stack itself is working
name.value.written.flatTap(logs =>IO(println(logs))).as(ExitCode.Success)
// this won't work
printLog(name).value.run.as(ExitCode.Success)
}
defprintLog[F[_], A](fa: F[A])(implicitF:Sync[F], FL:FunctorListen[F, Log]):F[A] = {
// this is never called when an error is raised
fa.listen.flatMap { case (a, logs) =>F.delay(println(logs)).as(a) }
}
defgetName[F[_]](implicitF:Sync[F], FT:FunctorTell[F, Log], FR:FunctorRaise[F, Throwable]):F[String] =for {
_ <-FT.tell(Vector("getting name ..."))
a <-F.delay("bob")
// Exception here means FunctorListen cant find any logs
_ <-FR.raise(newException("boom!")):F[Unit]
} yield a
}
I'm not sure if this is a problem with FunctorListen or FunctorRaise. It could be that FunctorRaise is raising an error at the IO level not the Either/EitherT
The text was updated successfully, but these errors were encountered:
I'm trying to stack a WriterT and EitherT together - ultimately something like IO[Writer[Log, Either[Throwable, A]]]. The idea is that even in the event of an error the log up to that point should be maintained.
I have created a POC which uses a transformer stack of EitherT[WriterT[IO, Log, *], Throwable, *] and when I materialise the program it works as expected. The logs are present even in the event of an error. However FunctorListen seems to short circuit in the event of an error. Here is the code itself:
I'm not sure if this is a problem with FunctorListen or FunctorRaise. It could be that FunctorRaise is raising an error at the IO level not the Either/EitherT
The text was updated successfully, but these errors were encountered: