-
-
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 CommutativeMonoid for Map #2098
Conversation
Since we already have a `Monoid` instance for `Map`, it seems natural to have a `CommutativeMonoid` when the value type has a commutative semigroup. Note: Unfortunately, I believe that this is a binary-incompatible change in cats kernel. cc @johnynek
Codecov Report
@@ Coverage Diff @@
## master #2098 +/- ##
==========================================
+ Coverage 94.65% 94.78% +0.12%
==========================================
Files 322 325 +3
Lines 5449 5488 +39
Branches 215 212 -3
==========================================
+ Hits 5158 5202 +44
+ Misses 291 286 -5
Continue to review full report at Codecov.
|
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.
Algebird is not using the instances object, so this won't burn algebird. @denisrosset can confirm if this will hurt spire.
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, will merge if we can confirm this won't affect Spire :)
Right now, Spire has its own instances; the proposed definition is sane and sound. I have a minor complaint: both the commutative and noncommutative tests of Consider changing the |
@denisrosset thanks for the review. You have a good point regarding the tests. Just to confirm that I understand you, you are suggesting leaving the new test as it is, but changing the existing |
@ceedubs, exactly. Not a big deal in this case, but a good habit to keep: try to not use for tests an instance that has more structure (i.e. commutativity) than required. |
@denisrosset 👍 that sounds like a good general guideline. Oh thanks @LukaJCB you beat me to it. |
a non commutative semigroup that does not accumulate in memory (like String) does is: This can be for any |
@johnynek on that note, wouldn't a simplified version be the "always first" semigroup? |
Indeed it would. |
Since we already have a
Monoid
instance forMap
, it seems natural tohave a
CommutativeMonoid
when the value type has a commutativesemigroup.
Note: Unfortunately, I believe that this is a binary-incompatible change in cats kernel. cc @johnynek