-
-
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
Add some more implementations to Function0 and Function1 Monads #3515
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3515 +/- ##
=======================================
Coverage 91.54% 91.54%
=======================================
Files 386 386
Lines 8476 8483 +7
Branches 217 246 +29
=======================================
+ Hits 7759 7766 +7
Misses 717 717 |
@@ -81,7 +81,10 @@ sealed private[instances] trait Function0Instances extends Function0Instances0 { | |||
() => (fa(), fb()) | |||
|
|||
override def ap[A, B](f: () => A => B)(fa: () => A): () => B = | |||
() => f().apply(fa()) |
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.
why was that .apply
here in the first place? does () => f()(fa())
work on dotty, maybe?
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.
I think it starts to look like a soup of parens, so I didn't write it that way.
|
||
override def ap[A, B](f: () => A => B)(fa: () => A): () => B = | ||
() => { | ||
val fnAB = f() |
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.
You can write this as either f.apply.apply(fa())
or f()(fa())
on Dotty, both of which are I think a little nicer than the extra val
.
This is just filling out some methods on these Monads that were left to default implementations. I think implementing them by hand slightly reduces the stack depth we are at when calling these