add Cats instances for C[_] given CollectionTag[C]#1834
add Cats instances for C[_] given CollectionTag[C]#1834bpholt wants to merge 1 commit intodisneystreaming:series/0.18from
Conversation
| * limitations under the License. | ||
| */ | ||
|
|
||
| package smithy4s.interopcats.internal |
There was a problem hiding this comment.
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.
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.
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.
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.