Effectie

website·Indexed 32 days ago

https://effectie.kevinly.dev

A library providing generic ways to construct effects and handle errors for tagless final code, with support for Cats Effect (v2 and v3), Monix, and Scalaz Effect. It includes typeclasses such as Fx, CanCatch, CanHandleError, and FromFuture for converting scala.concurrent.Future to effects, as well as support for OptionT and EitherT.

Tokens
21.1K
Snippets
96
Records
104
Agent score
56%

What's inside Effectie

  1. Overview of Effectie for FP Effect Libraries

    Effectie is a tool designed for Functional Programming (FP) Effect libraries, such as Cats Effect and Scalaz Effect. It enables developers to maintain abstractions in their code using the Tagless Final pattern and ensures referential transparency.
  2. Overview of Effectie

    v1
    Effectie is a set of type-classes and utilities designed for functional effect libraries, including Cats Effect, Monix, and Scalaz Effect. It provides a way to maintain referential transparency when constructing effect types within a tagless final architecture, specifically addressing issues where pure implementations in some libraries (like Cats Effect IO) may evaluate impure code immediately.
  3. Overview of Effectie

    Effectie is a set of type-classes and utilities designed for functional effect libraries such as Cats Effect, Monix, and Scalaz's Effect. It allows developers to write a single implementation of business logic that can be used across different effect types (e.g., IO and Future) without duplicating code, solving the common problem of maintaining separate implementations for different effect stacks.
  4. Overview of CanCatch for error handling

    CanCatch is a trait that allows catching NonFatal Throwable exceptions within an effect F[A] and converting them into a functional error representation F[Either[Throwable, A]]. In practice, you do not need to implement this trait directly because Fx already implements CanCatch.
    trait CanCatch[F[*]] {
      def catchNonFatal[A, B](fb: => F[B])(f: PartialFunction[Throwable, A]): F[Either[A, B]]
    
      def catchNonFatalEither[A, AA >: A, B](fab: => F[Either[A, B]])(
        f: PartialFunction[Throwable, AA]
      ): F[Either[AA, B]]
    }
  5. Catch NonFatal throwables using CanCatch

    v1
    The CanCatch[F] trait allows you to catch NonFatal Throwable instances occurring within an effect F[A] and transform them into a F[Either[Throwable, A]] (represented as F[A / B] in Scalaz). It requires a mapping function to convert the caught Throwable into a specific error type.
    trait CanCatch[F[*]] {
      def catchNonFatal[A, B](fb: => F[B])(f: Throwable => A): F[A \/ B]
    
      def catchNonFatalEither[A, B](fab: => F[A \/ B])(f: Throwable => A): F[A \/ B]
    
      def catchNonFatalEitherT[A, B](fab: => EitherT[F, A, B])(f: Throwable => A): EitherT[F, A, B]
    }
  6. Prevent program crashes using effectOf and pureOrError in Effectie

    In Effectie v2.5.0, effectOf and pureOrError are designed to catch errors, preventing the program from crashing due to unwanted exceptions. This functionality is supported when using Fx instances for Cats Effect 2 and 3, Monix 3, and Future.
  7. Catch NonFatal Throwables using CanCatch

    v1
    The CanCatch[F] trait allows developers to catch NonFatal Throwable instances occurring within an effect F[A] and transform them into an F[Either[A, B]]. It requires a mapping function to convert the caught Throwable into a custom error type.
    trait CanCatch[F[*]] {
      def catchNonFatal[A, B](fb: => F[B])(f: Throwable => A): F[Either[A, B]]
    
      def catchNonFatalEither[A, B](fab: => F[Either[A, B]])(f: Throwable => A): F[Either[A, B]]
    
      def catchNonFatalEitherT[A, B](fab: => EitherT[F, A, B])(f: Throwable => A): EitherT[F, A, B]
    }
  8. Convert scala.concurrent.Future to an effect using FromFuture

    FromFuture[F[*]] is a typeclass used to convert scala.concurrent.Future values into an effect type F[*]. This is particularly useful when integrating third-party APIs that return Future into an effect-based architecture. Instances are available for cats.effect.IO, scala.concurrent.Future, and cats.Id.
    trait FromFuture[F[*]] {
      def toEffect[A](future: => Future[A]): F[A]
    }
  9. Recover from NonFatal errors using the CanHandleError typeclass

    v1
    CanHandleError is a typeclass used to handle NonFatal Throwable instances and recover from them. It provides methods to intercept exceptions in both standard effect types F[A] and EitherT[F, A, B] structures. Instances are available for monix.eval.Task, scala.concurrent.Future, and cats.Id.
    trait CanHandleError[F[*]] {
    
      def handleNonFatalWith[A, AA >: A](
          fa: => F[A]
        )(
          handleError: Throwable => F[AA]
        ): F[AA]
    
      def handleEitherTNonFatalWith[A, AA >: A, B, BB >: B](
          efab: => EitherT[F, A, B]
        )(
          handleError: Throwable => F[Either[AA, BB]]
        ): EitherT[F, AA, BB]
    
      def handleNonFatal[A, AA >: A](
          fa: => F[A]
        )(
          handleError: Throwable => AA
        ): F[AA]
    
      def handleEitherTNonFatal[A, AA >: A, B, BB >: B](
          efab: => EitherT[F, A, B]
        )(
          handleError: Throwable => Either[AA, BB]
        ): EitherT[F, AA, BB]
    
    }
  10. Recover from NonFatal errors using CanHandleError

    CanHandleError is a typeclass used to handle and recover from NonFatal Throwable exceptions within an effect F. It provides mechanisms to catch exceptions and return a fallback value or a new effect. Instances are available for cats.effect.IO, scala.concurrent.Future, and cats.Id.
    trait CanHandleError[F[*]] {
    
      def handleNonFatalWith[A, AA >: A](
          fa: => F[A]
        )(
          handleError: Throwable => F[AA]
        ): F[AA]
    
      def handleEitherTNonFatalWith[A, AA >: A, B, BB >: B](
          efab: => EitherT[F, A, B]
        )(
          handleError: Throwable => F[Either[AA, BB]]
        ): EitherT[F, AA, BB]
    
      def handleNonFatal[A, AA >: A](
          fa: => F[A]
        )(
          handleError: Throwable => AA
        ): F[AA]
    
      def handleEitherTNonFatal[A, AA >: A, B, BB >: B](
          efab: => EitherT[F, A, B]
        )(
          handleError: Throwable => Either[AA, BB]
        ): EitherT[F, AA, BB]
    
    }
  11. Catch NonFatal Throwables using CanCatch

    v1
    The CanCatch[F] trait allows developers to intercept NonFatal Throwable exceptions occurring within an effect F[A] and transform them into an F[Either[A, B]]. It requires a mapping function to convert the caught Throwable into a custom error type.
    trait CanCatch[F[*]] {
      def catchNonFatal[A, B](fb: => F[B])(f: Throwable => A): F[Either[A, B]]
    
      def catchNonFatalEither[A, B](fab: => F[Either[A, B]])(f: Throwable => A): F[Either[A, B]]
    
      def catchNonFatalEitherT[A, B](fab: => EitherT[F, A, B])(f: Throwable => A): EitherT[F, A, B]
    }
  12. Catch non-fatal exceptions with CanCatch

    The CanCatch[F] trait allows you to catch NonFatal Throwable instances occurring within an effect F[A] and transform them into an F[Either[A, B]]. In practice, you do not need to implement this trait directly as Fx already provides CanCatch capabilities.
    trait CanCatch[F[*]] {
      def catchNonFatal[A, B](fb: => F[B])(f: PartialFunction[Throwable, A]): F[Either[A, B]]
    
      def catchNonFatalEither[A, AA >: A, B](fab: => F[Either[A, B]])(
        f: PartialFunction[Throwable, AA]
      ): F[Either[AA, B]]
    }