Skip to content

Conversation

@bpholt
Copy link
Contributor

@bpholt bpholt commented Sep 24, 2025

PR Checklist (not all items are relevant to all PRs)

  • Added unit-tests (for runtime code)
  • 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 behaviour
  • Added documentation
  • Updated changelog

There have been a few times that I've wanted to interact with a C[_] : CollectionTag using e.g. Functor[C] or Monad[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.

* limitations under the License.
*/

package smithy4s.interopcats.internal
Copy link
Contributor Author

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.

Copy link
Contributor

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.

@bpholt bpholt marked this pull request as ready for review September 24, 2025 18:03
CT: CollectionTag[C],
@annotation.unused IsSet: C[Any] =:= Set[Any]
): Traverse[C] with Monad[C] =
new instances.CatsInstancesForCollectionTag[C]
Copy link
Member

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
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants