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

optimize IO.whenA #4135

Merged
merged 3 commits into from
Sep 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading