Skip to content

Commit cb76f95

Browse files
authored
Merge pull request #4135 from Jasper-M/patch-1
optimize `IO.whenA`
2 parents 716e53e + 062120d commit cb76f95

File tree

1 file changed

+2
-3
lines changed
  • core/shared/src/main/scala/cats/effect

1 file changed

+2
-3
lines changed

core/shared/src/main/scala/cats/effect/IO.scala

+2-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ package cats.effect
1919
import cats.{
2020
Align,
2121
Alternative,
22-
Applicative,
2322
CommutativeApplicative,
2423
Eval,
2524
Functor,
@@ -1620,7 +1619,7 @@ object IO extends IOCompanionPlatform with IOLowPriorityImplicits {
16201619
* [[IO.raiseWhen]] for conditionally raising an error
16211620
*/
16221621
def whenA(cond: Boolean)(action: => IO[Unit]): IO[Unit] =
1623-
Applicative[IO].whenA(cond)(action)
1622+
if (cond) action else IO.unit
16241623

16251624
/**
16261625
* Returns the given argument if `cond` is false, otherwise `IO.Unit`
@@ -1631,7 +1630,7 @@ object IO extends IOCompanionPlatform with IOLowPriorityImplicits {
16311630
* [[IO.raiseWhen]] for conditionally raising an error
16321631
*/
16331632
def unlessA(cond: Boolean)(action: => IO[Unit]): IO[Unit] =
1634-
Applicative[IO].unlessA(cond)(action)
1633+
whenA(!cond)(action)
16351634

16361635
/**
16371636
* Returns `raiseError` when the `cond` is true, otherwise `IO.unit`

0 commit comments

Comments
 (0)