-
-
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
Instances of NonEmptyReducible are now available for implicit resolution #3541
Conversation
…ion. The type declared for NonEmptyVectorInstances.catsDataInstancesForNonEmptyVector and NonEmptyListInstances.catsDataInstancesForNonEmptyList explicitly declares them to implement NonEmptyReducible trait. This allows for abstractions over NonEmptyReducible.
|
…ion. The type declared for NonEmptyVectorInstances.catsDataInstancesForNonEmptyVector and NonEmptyListInstances.catsDataInstancesForNonEmptyList is reverted and doesn't explicitly declare NonEmptyReducible anymore. Instead, low-priority instances of NonEmptyReducible for non-empty list and non-empty vector are added.
…ion. Typo in the comments fixed.
…ion. Explicit type declaration is added for the newly defined instances.
Codecov Report
@@ Coverage Diff @@
## master #3541 +/- ##
=======================================
Coverage 91.30% 91.30%
=======================================
Files 386 386
Lines 8564 8568 +4
Branches 246 239 -7
=======================================
+ Hits 7819 7823 +4
Misses 745 745 |
👍 on green and no conflicts. I'm linking this to milestone 3 as the original implementation will be preferable when bincompat will not be an issue any more. |
@barambani so shall we just wait until cats 3? |
No this version adds value so I would merge it in in this compatible way. I think the only conflicts are due to the port to munit in the tests (but I haven't pulled you branch). I linked this PR to milestone 3 so that will be easier to remember to implement it in the original way when we will be free from the bincompat constraint. Sorry I didn't explain myself. |
@barambani thanks for the explanation. Should I resolve the merge conflict? |
@@ -329,8 +329,15 @@ final class NonEmptyVector[+A] private (val toVector: Vector[A]) | |||
NonEmptySet.of(head, tail: _*) | |||
} | |||
|
|||
sealed abstract private[data] class NonEmptyVectorInstances0 { |
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.
we could move this below NonEmptyVectorInstances
like it's done in NonEmptyListInstances0
. It's pretty conventional across the board and makes the read top to bottom easier.
|
||
implicit val catsDataNonEmptyReducibleNonEmptyList: NonEmptyReducible[NonEmptyList, List] = | ||
new NonEmptyReducible[NonEmptyList, List]() { | ||
override def split[A](fa: NonEmptyList[A]): (A, List[A]) = (fa.head, fa.tail) |
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.
now that we have this we could write split in here in terms of it. Something like
override def split[A](fa: NonEmptyList[A]): (A, List[A]) = catsDataNonEmptyReducibleNonEmptyList.split(fa)
and we could do the same for NonEmptyVector. The reason I'm suggesting this is I wouldn't want for someone to change the implementation of split in one place and get some inconsistent behaviour on the other instances.
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.
Thanks for the great point. Code duplication is never good.
Yes please, I also added two very minor comments. Thanks. |
…ion. NonEmptyVectorInstances0 are moved below NonEmptyVectorInstances.
…ion. catsDataInstancesForNonEmptyVector delegates implementation of split to catsDataNonEmptyReducibleNonEmptyVector. Same for List.
…ion. Conflicts with upstream/master resolved.
@barambani I've addressed your comments and resolved the merge conflicts. |
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.
👍
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.
@travisbrown |
@akopich apologies, I wasn't aware of these previous attempts and the final decision. |
@barambani nevermind. Anyway, doesn't the fact that the discussion of the matter has been initiated at least three times in the last year justify a need to expose at least some functionality of |
But |
The only method Personally I'd prefer to see us make |
@joroKr21 yeah, my bad. Actually I needed the head-tail decomposition, so I could implement |
@travisbrown but wouldn't making |
@akopich Right, it'd definitely break source-compatibility, but not binary compatibility, so in theory it could be done before Cats 3 (I doubt it's widely used outside of Cats, and could be provided in a compat library). I don't think it's really necessary to go that far, though—I just agree with you that this is confusing, and my preference would be to fix it as clearly as possible. |
@travisbrown IMO we can drastically decrease the number of similar PRs with a "it's not a bug" comment above the lines instantiating |
@akopich Would you want to open a PR adding that, and maybe a comment for |
@travisbrown ... and also add |
I think the documentation can happen first. We do want to use it internally, so I'm not sure deprecation is the right approach. |
The type declared for
NonEmptyVectorInstances.catsDataInstancesForNonEmptyVector
andNonEmptyListInstances.catsDataInstancesForNonEmptyList
explicitly declares them to implementNonEmptyReducible
trait now. This allows for abstractions over NonEmptyReducible.