-
-
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 a different MonoidK and SemigroupK instance for Kleisli #1098
Add a different MonoidK and SemigroupK instance for Kleisli #1098
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1098 +/- ##
==========================================
+ Coverage 96.07% 96.07% +<.01%
==========================================
Files 273 273
Lines 4538 4539 +1
Branches 119 117 -2
==========================================
+ Hits 4360 4361 +1
Misses 178 178
Continue to review full report at Codecov.
|
I got the syntax working with a type alias (so it can use the type T[f[_], a, b] = Function[a, f[b]]
val foo: T[Option, Int, Int] = x => if (x % 2 == 0) Some(x) else None
val bar: T[Option, Int, Int] = x => if (x % 3 == 0) Some(x) else None
foo <+> bar This looks quite a lot like |
f6fbd80
to
e112955
Compare
Looks good to me! 👍 |
@peterneyens thanks! It seems like it could potentially be problematic to have two different |
@ceedubs You are right, with this PR you will always get the newly added I'm not sure how often these new instances which combine |
Any updates on this? I don't see an issue with providing these instances explicitly, provided they're documented. |
Combine the result of Kleislis using MonoidK[F] or SemigroupK[F].
e112955
to
5e2b37f
Compare
c8172ba
to
2ab0e6d
Compare
2ab0e6d
to
eb8fa49
Compare
Made this instances explicit (notreally sure about the naming of the instances and the traits) and added doctests for both instances. Anything else you were thinking of @edmundnoble? |
@peterneyens do you still have time to work on this PR? If you want, I can continue this one or asking @ChristopherDavenport for the favor |
Could come back to this in the weekend, but if anybody else wants to go ahead in the mean time, I don't mind. |
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.
LGTM
Thanks so much @peterneyens |
Awesome! |
I was just looking at a StackOverflow question and was thinking this could be solved using
SemigroupK.combineK
, but while there is aSemigroupK[Option]
there is nothing to give us aSemigroupK[λ[α => Int => Option[α]]]
. So I have added aSemigroupK
andMonoidK
for a functionA => F[B]
if there is aMonoidK[F]
.I am not exactly sure how useful this is in practice. This is probably not something used very often (so I am not sure if this warrants inclusion in cats ?). It also seems you will always need to write a type lambda :
It would of course be nicer if you could write
foo <+> bar
. I'm not sure if that would be possible using the existingsemigroupSyntaxU
or using the SI-2712 fix (I tried with a locally published cats version with this PR and Miles' compiler plugin, but couldn't get it working) ?