Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

effectie v2.0.0 #638

Merged
merged 1 commit into from
Dec 1, 2024
Merged

effectie v2.0.0 #638

merged 1 commit into from
Dec 1, 2024

Conversation

kevin-lee
Copy link
Owner

2.0.0 - 2024-12-01

It also includes all the changes in the following releases.

2.0.0-beta1 - 2022-05-02

Done


2.0.0-beta2 - 2022-09-20

Renaming

Rename modules and packages (#430)

Modules

  • effectie-cats => effectie-syntax
  • effectie-cats-effect => effectie-cats-effect2
  • effectie-cats-effect3 remains the same
  • effectie-monix => effectie-monix3

Packages

  • Cats Effect 2: effectie.cats => effectie.ce2
  • Cats Effect 3: effectie.cats => effectie.ce3
  • Monix 3: effectie.monix => effectie.monix3

Project Structure Change


Added

  • Add FxCtor.pureOrError(a) and Fx.pureOrError(a) (Add FxCtor.pureOrError(a) and Fx.pureOrError(a) #424)
    FxCtor[IO].pureOrError(1)
    // IO[Int] = Pure(1)
    
    FxCtor[IO].pureOrError[Int]((throw new RuntimeException("ERROR")): Int)
    // IO[Int] = RaiseError(java.lang.RuntimeException("ERROR"))

Clean up


Documentation


2.0.0-beta3 - 2022-11-13

Packages

Details

  • move to effectie.instances: Move instances for Future to effectie.instances.future
  • Also add @implicitNotFound to show what to import
  • move to effectie.instances: Move instances for Id to effectie.instances.id
  • Remove instances for Id for Cats Effect 2 and 3 since they are now in the effectie-cats
  • Move ConsoleEffect instance to effectie.instances
  • Also effectie.instances.future.fromFuture.FromFutureToIdTimeout => effectie.core.FromFuture.FromFutureToIdTimeout
  • Remove instances for Id for Monix since they are now in the effectie-cats
  • Remove instances for IO for Monix since they are now in the effectie-cats-effect2
  • Move instances for IO and Task to effectie.instances

Added

ReleasableResource with Using and Try

import effectie.resource.ReleasableResource

ReleasableResource.usingResource(SomeAutoCloseable())
  .use { resource =>
    Try(resource.doSoemthing()) // Try[A]
  } // Try[A]

// OR

val trySomeResource: Try[SomeResource] = ...
ReleasableResource.usingResourceFromTry(trySomeResource)
  .use { resource =>
    Try(resource.doSoemthing()) // Try[A]
  } // Try[A]

ReleasableResource with Future

import effectie.resource.ReleasableResource
val futureResource: Future[SomeResource] = ...

ReleasableResource.futureResource(futureResource)
  .use { resource =>
    Future(doSomething(resource)) // Future[A]
  } // Future[A]

ReleasableResource with Cats Effect IO

  • Cats Effect 2

    import effectie.resource.Ce2Resource
    
    val fa: F[SomeResource] = ...
    
    Ce2Resource.fromAutoCloseable(fa)
      .use { resource =>
        Sycn[F].delay(doSomething(resource)) // F[A]
      } // F[A]
  • Cats Effect 3

    import effectie.resource.Ce3Resource
    
    val fa: F[SomeResource] = ...
    
    Ce3Resource.fromAutoCloseable(fa)
      .use { resource =>
        Sycn[F].delay(doSomething(resource)) // F[A]
      } // F[A]

2.0.0-beta4 - 2022-12-25 🎄

Changes


2.0.0-beta5 - 2023-01-14

New Features

  • Add ResourceMaker (Add ResourceMaker #468)

    ResourceMaker[F].forAutoCloseable[A <: AutoCloseable](fa: F[A]): ReleasableResource[F, A]
    import effectie.resource.ResourceMaker
    
    ResourceMaker.usingResourceMaker // ResourceMaker[Try]
    ResourceMaker.futureResourceMaker(implicit ec: ExecutionContext) // ResourceMaker[Future]
    import effectie.resource.Ce2ResourceMaker
    
    Ce2ResourceMaker.forAutoCloseable // ResourceMaker[F] where F[*]: Sync: BracketThrow
    import effectie.resource.Ce3Resource
    
    Ce3Resource.forAutoCloseable // ResourceMaker[F] where F[*]: Sync: MonadCancelThrow

Internal Housekeeping

  • cats-effect 3.3.5 => 3.3.14

2.0.0-beta6 - 2023-02-11

Change

  • Remove implicit fxCtor: FxCtor[F] param from the catch methods in CanCatch (Remove implicit fxCtor: FxCtor[F] param from the catch methods in CanCatch #480)

    The following methods in CanCatch

    def catchNonFatal[A, B](
      fb: => F[B]
    )(
      f: PartialFunction[Throwable, A]
    )(
      implicit fxCtor: FxCtor[F]
    ): F[Either[A, B]]
    
    def catchNonFatalEither[A, AA >: A, B](
      fab: => F[Either[A, B]]
    )(
      f: PartialFunction[Throwable, AA]
    )(
      implicit fxCtor: FxCtor[F]
    ): F[Either[AA, B]] 

    have been changed to

    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]] 

2.0.0-beta7 - 2023-02-25

New Features

Fix


2.0.0-beta8 - 2023-03-07

Changes

  • Remove unused implicit params (Remove unused implicit params #497)

    def catchNonFatal[A](
      f: PartialFunction[Throwable, A]
    )(
      implicit canCatch: CanCatch[F],
      fxCtor: FxCtor[F], // <= This is unused
    ): F[Either[A, B]] =
      canCatch.catchNonFatal[A, B](fb())(f)

    The implicit param fxCtor: FxCtor[F] has been removed.

  • Rename ConsoleEffect to ConsoleFx (Rename ConsoleEffect to ConsoleFx #499)

  • Move flatMapFa from CanCatch to FxCtor (Move flatMapFa from CanCatch to FxCtor #501)

    def flatMapFa[A, B](fa: F[A])(f: A => F[B]): F[B]
  • Move FxCtor from instance creation of ConsoleFx to each ConsoleFx method param (Move FxCtor from instance creation of ConsoleFx to each ConsoleFx method param #504)

    implicit def consoleFxF[F[*]: FxCtor: FlatMap]: ConsoleFx[F] = ...

    to

    trait ConsoleFx[F[*]] {
      def readLn(implicit fxCtor: FxCtor[F]): F[String]
    
      def readPassword(implicit fxCtor: FxCtor[F]): F[Array[Char]]
    
      def putStr(value: String)(implicit fxCtor: FxCtor[F]): F[Unit]
    
      def putStrLn(value: String)(implicit fxCtor: FxCtor[F]): F[Unit]
    
      def putErrStr(value: String)(implicit fxCtor: FxCtor[F]): F[Unit]
    
      def putErrStrLn(value: String)(implicit fxCtor: FxCtor[F]): F[Unit]
    
      def readYesNo(prompt: String)(implicit fxCtor: FxCtor[F]): F[YesNo]
    }
  • ConsoleFx instance should not depend on cats (Monad) (ConsoleFx instance should not depend on cats (Monad) #505)

    Instead, it depends on FxCtor now.


2.0.0-beta9 - 2023-03-18

New Feature

Internal Housekeeping


2.0.0-beta10 - 2023-07-15

New Feature

  • Add fromEffect(fa: => F[A]): F[A] to FxCtor and Fx (Add fromEffect(fa: => F[A]): F[A] to FxCtor and Fx #524)

    Fx[IO].fromEffect(IO(1)) // IO[Int]
    FxCtor[IO].fromEffect(IO(1)) // IO[Int]
  • Add make[A](fa: => F[A])(release: A => F[Unit]): ReleasableResource[F, A] to ResourceMaker[F[*]] (Add make[A](fa: => F[A])(release: A => F[Unit]): ReleasableResource[F, A] to ResourceMaker[F[*]] #527)

    def make[A](fa: => F[A])(release: A => F[Unit]): ReleasableResource[F, A]
    • Try

      val resourceMaker = ResourceMaker.usingResourceMaker
      resourceMaker
        .make(Try(new SomeResource()))(a => Try(a.release())) // ReleasableResource[Try, SomeResource]
        .use { someResource =>
          // do something with someResource
          Try(result) // Try[ResultType]
        } // Try[ResultType]
    • Future

      val resourceMaker = ResourceMaker.futureResourceMaker
      resourceMaker
        .make(Future(new SomeResource()))(a => Future(a.release())) // ReleasableResource[Future, SomeResource]
        .use { someResource =>
          // do something with someResource
          Future.successful(result) // Future[ResultType]
        } // Future[ResultType]
    • Cats Effect 2

      val resourceMaker = Ce2ResourceMaker.withResource
      resourceMaker
        .make(IO(new SomeResource()))(a => IO(a.release())) // ReleasableResource[IO, SomeResource]
        .use { someResource =>
          // do something with someResource
          IO.pure(result) // IO[ResultType]
        } // IO[ResultType]
    • Cats Effect 3

      val resourceMaker = Ce3ResourceMaker.withResource
      resourceMaker
        .make(IO(new SomeResource()))(a => IO(a.release())) // ReleasableResource[IO, SomeResource]
        .use { someResource =>
          // do something with someResource
          IO.pure(result) // IO[ResultType]
        } // IO[ResultType]
  • Add pure[A](a: A) and eval[A](fa: F[A]) to ResourceMaker (Add pure[A](a: A) and eval[A](fa: F[A]) to ResourceMaker #534)

    trait ResourceMaker[F[*]] {
      ...
    
      def pure[A](a: A): ReleasableResource[F, A]
    
      def eval[A](fa: F[A]): ReleasableResource[F, A]
    }
  • Add ReleasableResource.pure (Add ReleasableResource.pure #542)

    ReleasableResource.pure(resource: A): ReleasableResource[F, A]

    So A doesn't have to be AutoCloseable as it's just a pure value.

  • Add ReleasableResource.map and ReleasableResource.flatMap (Add ReleasableResource.map and ReleasableResource.flatMap #544)

    ReleasableResource.map(f: A => B)
    ReleasableResource.flatMap(f: A => ReleasableResource[F, B])
  • Add Functor type-class for ReleasableResource (Add Functor type-class for ReleasableResource #548)

  • Add Applicative type-class for ReleasableResource (Add Applicative type-class for ReleasableResource #550)

Changes


2.0.0-beta11 - 2023-07-22

Fixed


2.0.0-beta12 - 2023-09-09

New Features

  • Add CanRestart for retrying F[A] (Add CanRestart for retrying F[A] #566)

    trait CanRestart[F[*]] {
      def restartWhile[A](fa: F[A])(p: A => Boolean): F[A]
    
      def restartUntil[A](fa: F[A])(p: A => Boolean): F[A]
    
      def restartOnError[A](fa: F[A])(maxRetries: Long): F[A]
    
      def restartOnErrorIfTrue[A](fa: F[A])(p: Throwable => Boolean): F[A]
    }
  • Add instances of CanCatch, CanHandleError, CanRecover, FromFuture, Fx and FxCtor with Sync and Async (Add instances of CanCatch, CanHandleError, CanRecover, FromFuture, Fx and FxCtor with Sync and Async #568)

    So it can be done like this with the effectie.instances.ce2.f and effectie.instances.ce3.f packages.

    def foo[F[*]: Fx](n: Int): F[Int] = Fx[F].effectOf(n * 2)
    
    // Fx[F] can be satisfied with just Sync[F] like this.
    import effectie.instances.ce2.f.fx._
    def bar[F[*]: Sync](n: Int): F[Int] = foo(n)

2.0.0-beta13 - 2023-10-01

Changes

New Feature

  • rethrowIfLeft and rethrowTIfLeft syntax for F[Either[A, B]] and EitherT[F, A, B] (rethrowIfLeft and rethrowTIfLeft syntax for F[Either[A, B]] and EitherT[F, A, B] #588)

    val fa: IO[Either[Throwable, Int]] = pureOf[IO](Right(1))
    fa.rethrowIfLeft
    // IO[Int] = IO(1)
    val fa: IO[Either[Throwable, Int]] = pureOf[IO](Left(new RuntimeException("Error")))
    fa.rethrowIfLeft
    // IO[Int] = RaiseError(RuntimeException("ERROR"))
    val fa: EitherT[IO, Throwable, Int] = pureOf[IO](Right(1)).eitherT
    fa.rethrowTIfLeft
    // IO[Int] = IO(1)
    val fa: EitherT[IO, Throwable, Int] = pureOf[IO](Left(new RuntimeException("Error"))).eitherT
    fa.rethrowTIfLeft
    // IO[Int] = RaiseError(RuntimeException("ERROR"))

2.0.0-beta14 - 2024-01-12

New Feature

@kevin-lee kevin-lee added this to the v2-m1 milestone Dec 1, 2024
@kevin-lee kevin-lee self-assigned this Dec 1, 2024
@github-actions github-actions bot added pr PR release Release v2 Effectie v2 labels Dec 1, 2024
Copy link

codecov bot commented Dec 1, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.48%. Comparing base (d87f348) to head (e9868d4).
Report is 2 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #638   +/-   ##
=======================================
  Coverage   94.48%   94.48%           
=======================================
  Files          81       81           
  Lines         544      544           
  Branches       20       20           
=======================================
  Hits          514      514           
  Misses         30       30           

@kevin-lee kevin-lee merged commit 71435d2 into main Dec 1, 2024
16 checks passed
@kevin-lee kevin-lee deleted the prepare-to-release branch December 1, 2024 10:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr PR release Release v2 Effectie v2
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant