That is what == does: https://github.com/apple/swift/blob/master/stdlib/public/core/HashedCollections.swift.gyb#L1267
> On Oct 15, 2017, at 1:25 PM, C. Keith Ray via swift-evolution > <swift-evolution@swift.org> wrote: > > Why not use an equals Implementation that doesn't rely on order? > > Something like this (which doesn't compile in my iPad playground). If two > sets have the same number of elements, and every element in one can be found > in the other, they are equal, otherwise they are not equal. > > protocol Set { > static func == (lhs: Self, rhs: Self) { > guard lhs.count == rhs.count else { return false } > for x in lhs { > if !rhs.contains(x) { return false } > } > return true > } > } > > -- > C. Keith Ray > > * https://leanpub.com/wepntk <https://leanpub.com/wepntk> <- buy my book? > * http://www.thirdfoundationsw.com/keith_ray_resume_2014_long.pdf > <http://www.thirdfoundationsw.com/keith_ray_resume_2014_long.pdf> > * http://agilesolutionspace.blogspot.com/ > <http://agilesolutionspace.blogspot.com/> > > On Oct 15, 2017, at 12:40 PM, Kevin Nattinger via swift-evolution > <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote: > >>> […] >>> Swift's Sequence protocol does not require the order of iteration to >>> "convey any meaning"; it doesn't even require it to be deterministic. >>> >> >> And that’s EXACTLY why none of the functions on Sequence should rely on the >> order conveying meaning. `ElementsEqual` (for example) DOES rely on the >> order of iteration conveying a meaning not required by the protocol, and >> renaming it `lexicographicallyEquals` does not change that fact. Either >> Sequence needs to require a meaningful order or `elementsEqual` should be >> moved to a protocol that does. >> >> _______________________________________________ >> swift-evolution mailing list >> swift-evolution@swift.org <mailto:swift-evolution@swift.org> >> https://lists.swift.org/mailman/listinfo/swift-evolution >> <https://lists.swift.org/mailman/listinfo/swift-evolution> > _______________________________________________ > swift-evolution mailing list > swift-evolution@swift.org > https://lists.swift.org/mailman/listinfo/swift-evolution
_______________________________________________ swift-evolution mailing list swift-evolution@swift.org https://lists.swift.org/mailman/listinfo/swift-evolution