apple / swift-experimental-string-processing

An early experimental general-purpose pattern matching engine for Swift.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

hitsvilleusa opened this issue · comments

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

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.