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 11, 2023
1 parent afe219a commit d6f9f68
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions kernel/shared/src/main/scala/cats/effect/kernel/GenSpawn.scala
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,27 @@ trait GenSpawn[F[_], E] extends MonadCancel[F, E] with Unique[F] {
*/
def cede: F[Unit]

/**
* Functor map, but causes a reschedule before and after `f`
*/
def cedeMap[A, B](fa: F[A])(f: A => B): F[B] =
for {
a <- fa
_ <- cede
b = f(a)
_ <- cede
} yield b

/**
* Causes a reschedule before and after `fa`
*/
def intercede[A](fa: F[A]): F[A] =
for {
_ <- cede
a <- fa
_ <- cede
} yield a

/**
* A low-level primitive for racing the evaluation of two fibers that returns the [[Outcome]]
* of the winner and the [[Fiber]] of the loser. The winner of the race is considered to be
Expand Down

0 comments on commit d6f9f68

Please sign in to comment.