Skip to content
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

contains<C>(_:) does not behave as expected #694

Open
hitsvilleusa opened this issue Sep 28, 2023 · 1 comment
Open

contains<C>(_:) does not behave as expected #694

hitsvilleusa opened this issue Sep 28, 2023 · 1 comment

Comments

@hitsvilleusa
Copy link

Because this is defined on Collection it is available to all Collection types, not just String. The behavior on other types is odd at best. It isn't even predictable when working with a Set. I think it should either be fixed to behave as expected, or narrowed down to just work on String?

Attached is an example playground to experiment with which demonstrates the issue.

Contains.playground.zip

@natecook1000
Copy link
Member

For collection types like Set and Dictionary that are semantically unordered (i.e. their order isn't guaranteed to be the same each time you run a program), any API that requires semantic ordering won't really be usable. The same is true for standard library collection algorithms like starts(with:) and equalElements(_:).

For ordered collections, like strings, arrays, buffers, and many of the collection types in swift-collections, the contains method works just as you'd expect.

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

No branches or pull requests

2 participants