Skip to content

Commit 3714fd7

Browse files
committed
Reduce bolierplate in IO implementation of computeMap & computeMapAttempt
1 parent 864b4a5 commit 3714fd7

File tree

1 file changed

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

1 file changed

+3
-3
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ sealed abstract class IO[+A] private () extends IOPlatform[A] {
587587
* [[cede]] for more details
588588
*/
589589
def computeMap[B](f: A => B): IO[B] =
590-
IO.cede >> map(f).guarantee(IO.cede)
590+
this.flatMap(a => IO.compute(f(a)))
591591

592592
/**
593593
* Like [[computeMap]], but allows raising errors in an Either.
@@ -596,7 +596,7 @@ sealed abstract class IO[+A] private () extends IOPlatform[A] {
596596
* [[computeMap]] for more details
597597
*/
598598
def computeMapAttempt[B](f: A => Either[Throwable, B]): IO[B] =
599-
IO.cede >> flatMap(a => IO.fromEither(f(a))).guarantee(IO.cede)
599+
this.flatMap(a => IO.computeAttempt(f(a)))
600600

601601
/**
602602
* Applies rate limiting to this `IO` based on provided backpressure semantics.
@@ -1323,7 +1323,7 @@ object IO extends IOCompanionPlatform with IOLowPriorityImplicits with TuplePara
13231323
* [[compute]] for more details
13241324
*/
13251325
def computeAttempt[A](thunk: => Either[Throwable, A]): IO[A] =
1326-
IO.cede >> delay(thunk).rethrow.guarantee(IO.cede)
1326+
IO.cede >> IO.delay(thunk).rethrow.guarantee(IO.cede)
13271327

13281328
/**
13291329
* Suspends a synchronous side effect which produces an `IO` in `IO`.

0 commit comments

Comments
 (0)