From afe219ada9c2e6a3fa4c2379113668375c9db11f Mon Sep 17 00:00:00 2001 From: Tyler Chan Date: Tue, 10 Jan 2023 21:03:08 +0800 Subject: [PATCH] Add two new combinators: `cedeMap` and `intercede` --- .../src/main/scala/cats/effect/IO.scala | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/core/shared/src/main/scala/cats/effect/IO.scala b/core/shared/src/main/scala/cats/effect/IO.scala index 1745047899..68b26b1ddb 100644 --- a/core/shared/src/main/scala/cats/effect/IO.scala +++ b/core/shared/src/main/scala/cats/effect/IO.scala @@ -497,6 +497,20 @@ sealed abstract class IO[+A] private () extends IOPlatform[A] { */ def map[B](f: A => B): IO[B] = IO.Map(this, f, Tracing.calculateTracingEvent(f)) + /** + * Functor map, but causes a reschedule before and after `f`. For more information, checkout + * `cede` in the companion object. + */ + def cedeMap[B](f: A => B): IO[B] = + (this <* IO.cede).map(a => f(a)).guarantee(IO.cede) + + /** + * Causes a reschedule before and after `fa`. For more information, checkout `cede` in the + * companion object. + */ + def intercede: IO[A] = + IO.cede *> this.guarantee(IO.cede) + /** * Applies rate limiting to this `IO` based on provided backpressure semantics. * @@ -1316,18 +1330,6 @@ object IO extends IOCompanionPlatform with IOLowPriorityImplicits { */ def cede: IO[Unit] = Cede - /** - * Functor map, but causes a reschedule before and after `f` - */ - def cedeMap[A, B](fa: IO[A])(f: A => B): IO[B] = - (fa <* cede).map(a => f(a)).guarantee(cede) - - /** - * causes a reschedule before and after `fa` - */ - def intercede[A](fa: IO[A]): IO[A] = - cede *> fa.guarantee(cede) - /** * This is a low-level API which is meant for implementors, please use `background`, `start`, * `async`, or `Deferred` instead, depending on the use case