-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Optimize Apply
methods in FlatMap
#2597
Conversation
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.
👍
Codecov Report
@@ Coverage Diff @@
## master #2597 +/- ##
==========================================
+ Coverage 95.16% 95.16% +<.01%
==========================================
Files 361 361
Lines 6634 6638 +4
Branches 294 295 +1
==========================================
+ Hits 6313 6317 +4
Misses 321 321
Continue to review full report at Codecov.
|
I think that this is probably a good change to make, but I'm wondering if it should go into a new minor version as opposed to a patch. My concern is that someone might have an In fact I wonder whether this might apply to our instances for standard library |
@ceedubs this is probably not a breaking change because currently map(flatMap(fa)(a => map(fb)(b => (a, b))))((a, _) => a)
map(flatMap(fa)(a => map(fb)(b => (a, b))))((_, b) => b) You can see wasteful So I don't blieve this change will change the effect. |
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.
Ah, okay thanks for the explanation @kailuowang. This sounds good to me (but maybe we should let this hang around just a bit longer in case anyone else has concerns).
flatMap(fa)(a => map(fb)(b => f(a, b))) | ||
|
||
override def productR[A, B](fa: F[A])(fb: F[B]): F[B] = | ||
flatMap(fa)(_ => fb) |
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.
Coming back to this, the lack of symmetry between productR
and productL
feels a little off to me. I think that the override of map2
makes sense. But maybe productL
and productR
should both just delegate to map2
?
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.
Unlike productL
, productR
using map2
will incur one extra map
. That's where the asymmetry comes from.
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.
Oh right. Sorry that I've required so much explanation on this one 😬
LGTM. @mpilquist does this PR look good to you?
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.
Yep looks good to me
I noticed that these implementations can be slightly improved. Given their common usages I think it would worth it.
related issue typelevel/cats-effect#401