-
Notifications
You must be signed in to change notification settings - Fork 534
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
base: series/3.x
Are you sure you want to change the base?
Changes from 3 commits
ace83fc
afe219a
d6f9f68
9b2ba64
ed15013
a5b8670
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -282,6 +282,27 @@ trait GenSpawn[F[_], E] extends MonadCancel[F, E] with Unique[F] { | |||||||||||||||||
*/ | ||||||||||||||||||
def cede: F[Unit] | ||||||||||||||||||
Comment on lines
282
to
283
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
|
||||||||||||||||||
/** | ||||||||||||||||||
* Functor map, but causes a reschedule before and after `f` | ||||||||||||||||||
*/ | ||||||||||||||||||
Comment on lines
+285
to
+287
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
def cedeMap[A, B](fa: F[A])(f: A => B): F[B] = | ||||||||||||||||||
for { | ||||||||||||||||||
a <- fa | ||||||||||||||||||
_ <- cede | ||||||||||||||||||
b = f(a) | ||||||||||||||||||
_ <- cede | ||||||||||||||||||
} yield b | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for adding these! Is there a particular reason you wrote them as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
No, it's I just can't find *> and <* combinators here. 🤦 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh, were they not compiling? They come from here:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, I missed the fact that MonadCancel is cats Monad! Will change that in a minute. |
||||||||||||||||||
|
||||||||||||||||||
/** | ||||||||||||||||||
* Causes a reschedule before and after `fa` | ||||||||||||||||||
*/ | ||||||||||||||||||
Comment on lines
+291
to
+293
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||
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 | ||||||||||||||||||
|
There was a problem hiding this comment.
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 inF[_]
and take the effect as an argument (instead of instance methods).cats-effect/kernel/shared/src/main/scala/cats/effect/kernel/GenSpawn.scala
Line 283 in 130fdcc