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

Add two new combinators: cedeMap and intercede #3353

Open
wants to merge 6 commits into
base: series/3.x
Choose a base branch
from
Open
Changes from 2 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
14 changes: 14 additions & 0 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)
Comment on lines +500 to +512
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Would you mind adding versions of these methods to GenSpawn in the kernel module? These would be more similar to your original definitions, which are in F[_] and take the effect as an argument (instead of instance methods).


/**
* Applies rate limiting to this `IO` based on provided backpressure semantics.
*
Expand Down