effectie.instances.ce2.canRecover.scala Maven / Gradle / Ivy
The newest version!
package effectie.instances.ce2
import cats.*
import cats.data.EitherT
import cats.effect.*
import effectie.core.CanRecover
import scala.concurrent.{ExecutionContext, Future}
import scala.util.control.NonFatal
/** @author Kevin Lee
* @since 2020-08-17
*/
object canRecover {
given ioCanRecover: CanRecover[IO] with {
inline override def recoverFromNonFatalWith[A, AA >: A](fa: => IO[A])(
handleError: PartialFunction[Throwable, IO[AA]]
): IO[AA] =
fa.handleErrorWith(err => handleError.applyOrElse(err, ApplicativeError[IO, Throwable].raiseError[AA]))
inline override def recoverFromNonFatal[A, AA >: A](fa: => IO[A])(
handleError: PartialFunction[Throwable, AA]
): IO[AA] =
recoverFromNonFatalWith[A, AA](fa)(handleError.andThen(IO.pure(_)))
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy