On the elementsEqual problem, or “[Pitch] Set and Dictionary should not be Sequences”

This is not only a problem for pedantic language lawyers, but also for people new to Swift, and even for seasoned Swift developers aiming to add new functionality to the standard library:

Similarly to the case of elementsEqual, it probably seemed straight-forward to add a method that checks whether a collection contains another collection:

contains<T: Collection>(_ other: T) -> Bool where T.Element == Element

But as soon as we realize that Set and String will also get this method, and that it will sit side by side with Set's isSuperset(of: ) and NSStrings contains(other: StringProtocol), things get more complicated, and we try to resolve it by changing the name to sequentuallyContains or perhaps rather containsCollection or something.

5 Likes