-
Couldn't load subscription status.
- Fork 89
add Cats instances for C[_] given CollectionTag[C] #1834
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
base: series/0.18
Are you sure you want to change the base?
Conversation
| * limitations under the License. | ||
| */ | ||
|
|
||
| package smithy4s.interopcats.internal |
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 put this in .internal so that it wouldn't be imported if someone did import smithy4s.interopcats.*. I'm happy to put it somewhere else if desired.
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.
If it's in .internal, it means that users should really not use it (yourself included), put it in smithy.interopcats instead.
| CT: CollectionTag[C], | ||
| @annotation.unused IsSet: C[Any] =:= Set[Any] | ||
| ): Traverse[C] with Monad[C] = | ||
| new instances.CatsInstancesForCollectionTag[C] |
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.
question: can you elaborate on why we have a separate instance for sets?
Cats normally doesn't even provide a functor for Set because of ordering problems and so on.
In addition, in a polymorphic context you won't see a value of C[Any] =:= Set[Any] (because the compiler can't know C is Set at that point), and it'd only be useful after you've matched specifically to case SetTag, at which point we might as well just provide a Traverse[Set].
| ): Traverse[C] with Monad[C] = | ||
| new instances.CatsInstancesForCollectionTag[C] | ||
|
|
||
| implicit def catsInstancesGivenCollectionTag[C[_]](implicit |
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.
thought: wonder if we can avoid the NotGiven check by putting this in a separate trait (also inherited by this object), playing with implicit priority like Cats does with its own instances. That'd be a nice way to get rid of the scala2 NotGiven.
PR Checklist (not all items are relevant to all PRs)
Added bootstrapped code + smoke tests (when the rendering logic is modified)Added build-plugins integration tests (when reflection loading is required at codegen-time)Added alloy compliance tests (when simpleRestJson protocol behaviour is expanded/updated)Updated dynamic module to match generated-code behaviourThere have been a few times that I've wanted to interact with a
C[_] : CollectionTagusing e.g.Functor[C]orMonad[C]. I was able to build lawful instances so I thought this would be a useful contribution.I'll update the changelog if/once there's consensus that this is otherwise ready to merge. Happy to add documentation, too, although I'm not sure exactly where.