From 9d6d7f2c0e52457db7a6628854953d3bd3d91434 Mon Sep 17 00:00:00 2001 From: Jasper Moeys Date: Thu, 12 Sep 2024 15:11:16 +0200 Subject: [PATCH 1/3] optimize IO.whenA --- core/shared/src/main/scala/cats/effect/IO.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/shared/src/main/scala/cats/effect/IO.scala b/core/shared/src/main/scala/cats/effect/IO.scala index 989d405114..40f0db1b9e 100644 --- a/core/shared/src/main/scala/cats/effect/IO.scala +++ b/core/shared/src/main/scala/cats/effect/IO.scala @@ -1620,7 +1620,7 @@ object IO extends IOCompanionPlatform with IOLowPriorityImplicits { * [[IO.raiseWhen]] for conditionally raising an error */ def whenA(cond: Boolean)(action: => IO[Unit]): IO[Unit] = - Applicative[IO].whenA(cond)(action) + if (cond) action else IO.unit /** * Returns the given argument if `cond` is false, otherwise `IO.Unit` @@ -1631,7 +1631,7 @@ object IO extends IOCompanionPlatform with IOLowPriorityImplicits { * [[IO.raiseWhen]] for conditionally raising an error */ def unlessA(cond: Boolean)(action: => IO[Unit]): IO[Unit] = - Applicative[IO].unlessA(cond)(action) + whenA(!cond)(action) /** * Returns `raiseError` when the `cond` is true, otherwise `IO.unit` From 72d547c87c881244165ef4fdc1e06e6eff6d6691 Mon Sep 17 00:00:00 2001 From: Jasper Moeys Date: Thu, 12 Sep 2024 17:42:21 +0200 Subject: [PATCH 2/3] clean up imports --- .../src/main/scala/cats/effect/IO.scala | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/core/shared/src/main/scala/cats/effect/IO.scala b/core/shared/src/main/scala/cats/effect/IO.scala index 40f0db1b9e..c2083aeb7e 100644 --- a/core/shared/src/main/scala/cats/effect/IO.scala +++ b/core/shared/src/main/scala/cats/effect/IO.scala @@ -16,24 +16,7 @@ package cats.effect -import cats.{ - Align, - Alternative, - Applicative, - CommutativeApplicative, - Eval, - Functor, - Id, - Monad, - Monoid, - Now, - Parallel, - Semigroup, - SemigroupK, - Show, - StackSafeMonad, - Traverse -} +import cats.{Align, Alternative, CommutativeApplicative, Eval, Functor, Id, Monad, Monoid, Now, Parallel, Semigroup, SemigroupK, Show, StackSafeMonad, Traverse} import cats.data.Ior import cats.effect.instances.spawn import cats.effect.kernel.CancelScope From 062120db8c6fd3121e39c358d4cbca50160c587b Mon Sep 17 00:00:00 2001 From: Jasper Moeys Date: Thu, 12 Sep 2024 17:49:24 +0200 Subject: [PATCH 3/3] scalafmt --- .../shared/src/main/scala/cats/effect/IO.scala | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/core/shared/src/main/scala/cats/effect/IO.scala b/core/shared/src/main/scala/cats/effect/IO.scala index c2083aeb7e..49185821a6 100644 --- a/core/shared/src/main/scala/cats/effect/IO.scala +++ b/core/shared/src/main/scala/cats/effect/IO.scala @@ -16,7 +16,23 @@ package cats.effect -import cats.{Align, Alternative, CommutativeApplicative, Eval, Functor, Id, Monad, Monoid, Now, Parallel, Semigroup, SemigroupK, Show, StackSafeMonad, Traverse} +import cats.{ + Align, + Alternative, + CommutativeApplicative, + Eval, + Functor, + Id, + Monad, + Monoid, + Now, + Parallel, + Semigroup, + SemigroupK, + Show, + StackSafeMonad, + Traverse +} import cats.data.Ior import cats.effect.instances.spawn import cats.effect.kernel.CancelScope