-
-
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
Replace type class composition with Nested data type #1021
Conversation
We currently use cats.data.Prod for product composition - for consistency, and for reasons outlined in typelevel#968, I think we should use a cats.data.Compose data type for nested composition. I did the usual type classes first. No tests are added intentionally, putting this up as a proof of concept. If nobody yells at me for a couple of days I'll assume everything is OK and I'll clean things up, add comments, tests, etc.
Tests not passing is expected since I removed a bunch of stuff, I'll add them assuming folks are OK with this proof of concept. |
I don't have a super strong opinion on this, but I think that I like it. I'd be interested to see some real-worldish examples of using it. For example how verbose do you need to be to use it with I admit that I pretty much never use type class |
So the reasons I've wanted this in in contexts where I'm working with a nested structure and I'm doing something like For the |
Current coverage is 89.32%
@@ master #1021 diff @@
==========================================
Files 224 216 -8
Lines 2842 2752 -90
Methods 2785 2691 -94
Messages 0 0
Branches 52 58 +6
==========================================
- Hits 2505 2458 -47
+ Misses 337 294 -43
Partials 0 0
|
Don't understand this build fail thing, but yay +0.24%! |
👏 I haven't done a thorough review yet, but at first glance this looks promising. |
So I like the ability to wrap a data structure in |
The idea is if you have Among the other motivations for replacing |
I guess one difference between this and the product case is that in the product case you have to return a different type (something like I like |
My worry is that if someone has something like |
Ah fair point - I will try to get that work in sometime this week. I think my plan will be:
Thoughts? |
Nested instances are no longer wrapped in Nested, but instances delegate to the unwrapped instances.
Done! |
Hey @adelbertc! This looks really good. I like the design but one thing I found confusing was the distinction between the anonymous type classes (in terms of Could we split |
Sounds good, I will make the change this week. |
@non The only thing that bothers me slightly is having the methods called |
It occurs to me maybe |
I guess my feeling is that there are two things here and I would like to keep them distinct:
I would prefer not to use very similar names for both of these, since they are somewhat different. I was happy with using nest/nested for (1) and compose/composed for (2), but if you don't like those names let's figure something else out. |
I can buy into that, I'll try to work on it tonight or tomorrow :-) |
- Rename unwrapped composed instances to Composed instead of Nested - Move instances to Composed.scala - Rename methods from nest to compose
Good to go! |
👍 thanks @adelbertc! |
I'm not sure, but since the |
The reason I didn't keep them in their respective type class tests was because I didn't want them all scattered around |
OK, that seems a good idea, but don't we need something like |
So I did a perhaps questionable trick - the |
Ah OK now I see. I clearly didn't gave the Thank you for explaining ! |
👍 Thanks @adelbertc |
We currently use cats.data.Prod for product composition -
for consistency, and for reasons outlined in #968, I think
we should use a cats.data.Compose data type for nested
composition.
I did the usual type classes first. No tests are added
intentionally, putting this up as a proof of concept. If
nobody yells at me for a couple of days I'll assume everything
is OK and I'll clean things up, add comments, tests, etc.
EDIT: I also realized we have
cats.arrow.Compose
.. what do we want to do about that? (assuming we want this to move forward)EDIT2: Maybe we call it
Nested
.. like nested composition.. andProd
for product composition..