pointfreeco / swift-identified-collections

A library of data structures for working with collections of identifiable elements in an ergonomic, performant way.
MIT License
539 stars 46 forks source link

Add container protocol for generic constraints #56

Closed mjarvis closed 1 year ago

mjarvis commented 1 year ago

Similar to swift protocols such as Collection, Sequence, etc.

This provides a protocol with the main functionality of IdentifiedArray for use in generic constraints for types which can support some protocol IdentifiedArray conforms to. (see example in tests using T: Collection), allowing types to provide specialized functionality for given containers.

Before continuing on the todo list below, I wanted to provide this simple sample to see if this is something that would be considered for merge. I am currently using a similar protocol in a project by extending IdentifiedArray to conform outside of this package, but figured it may be useful for others.

TODO:

stephencelis commented 1 year ago

Hey @mjarvis! A protocol definitely could be interesting if we come up with more identified collection conformances, but given that we have a single one, is there any reason you couldn't use the concrete type instead? Do you have some use cases in mind you could share?

stephencelis commented 1 year ago

@mjarvis I'm going to close this for now, since I'm having a hard time understanding the use case vs. a concrete type, but please open a discussion if you'd like to chat about it more, and then we can consider opening this PR again.

mjarvis commented 1 year ago

Sorry for the lack of response @stephencelis, if I find time to expand on this and provide the use cases I'll open a discussion.