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
Bracket typeclass, that exists in cats-effect, doesn't work well with an effect that relies on FunctorRaise.
I want to implement a clean-up logic in case of any error (raised either by MonadError or FunctorRaise).
Example:
importcats.data.EitherTimportcats.effect._importcats.effect.syntax.bracket._importcats.mtl._importcats.mtl.implicits._finalcaseclassAppError(reason: String)
classService[F[_]:Sync:ApplicativeHandle[?[_], AppError]:FunctorRaise[?[_], AppError]] {
defcreateActive:F[String] =
create.bracketCase(uuid => makeActive(uuid)) {
case (_, ExitCase.Completed) =>Sync[F].unit // There can be an error toocase (uuid, ExitCase.Error(e)) => destroy(uuid)
case (uuid, ExitCase.Canceled) => destroy(uuid)
}
defmakeActive(uuid: String):F[String] =FunctorRaise[F, AppError].raise(AppError("Oops. Something went wrong"))
defcreate:F[String] =Sync[F].pure("some uuid")
defdestroy(uuid: String):F[Unit] =Sync[F].unit
}
objectService {
defmain(args: Array[String]):Unit= {
typeEffect[A] =EitherT[IO, AppError, A]
valservice=newService[Effect]
println(service.createActive.value.unsafeRunSync()) // Left(AppError("Oops. Something went wrong"))
}
}
For sure this is the correct behavior of a Bracket typeclass and clean-up logic for a specific error can be managed inside the bracket:
Hi all.
Bracket typeclass, that exists in cats-effect, doesn't work well with an effect that relies on FunctorRaise.
I want to implement a clean-up logic in case of any error (raised either by MonadError or FunctorRaise).
Example:
For sure this is the correct behavior of a Bracket typeclass and clean-up logic for a specific error can be managed inside the bracket:
But should there be an alternative Bracket that manages specific errors raised by FunctorRaise? For example, extended ADT can be used:
The text was updated successfully, but these errors were encountered: