Skip to content

Commit

Permalink
Merge pull request #4135 from Jasper-M/patch-1
Browse files Browse the repository at this point in the history
optimize `IO.whenA`
  • Loading branch information
djspiewak authored Sep 23, 2024
2 parents 716e53e + 062120d commit cb76f95
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions core/shared/src/main/scala/cats/effect/IO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package cats.effect
import cats.{
Align,
Alternative,
Applicative,
CommutativeApplicative,
Eval,
Functor,
Expand Down Expand Up @@ -1620,7 +1619,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`
Expand All @@ -1631,7 +1630,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`
Expand Down

0 comments on commit cb76f95

Please sign in to comment.