Skip to content

Commit

Permalink
Add two new combinators: cedeMap and intercede
Browse files Browse the repository at this point in the history
  • Loading branch information
biuld committed Jan 10, 2023
1 parent ace83fc commit afe219a
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions core/shared/src/main/scala/cats/effect/IO.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit afe219a

Please sign in to comment.