[swift-evolution] [Draft] Rename Sequence.elementsEqual

Kevin Nattinger swift at nattinger.net
Mon Oct 16 12:19:51 CDT 2017

>> […]
>> Set conforming to Collection is even worse than just conforming to Sequence as a quote from the documentation shows: "In addition to the operations that collections inherit from the Sequence protocol, you gain access to methods that depend on accessing an element at a specific position in a collection."
>> Clearly the elements of a Set do not have specific positions.
> That’s not at all clear to me, could you elaborate? My understanding is that elements of Set definitely *do* have a position, and that’s why you can use an index on a set to retrieve the element. The same index on the same set retrieves the same element.

A Set only has "indices" because it confirms to a protocol where almost all the requirements are meaningless for an unordered collection. Or at best, for the same reason it has an "order": as a side-effect of the fact that it can be iterated over, you can give indices for each element on a specific iteration; those indices are meaningless for the set itself, and should not be used for anything but a full, order-independent iteration.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171016/a619a78f/attachment.html>

More information about the swift-evolution mailing list