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

C. Keith Ray keithray at mac.com
Sun Oct 15 15:25:07 CDT 2017


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 <- buy my book?
* http://www.thirdfoundationsw.com/keith_ray_resume_2014_long.pdf
* http://agilesolutionspace.blogspot.com/

> On Oct 15, 2017, at 12:40 PM, Kevin Nattinger via swift-evolution <swift-evolution at 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 at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171015/eb6ce61f/attachment.html>


More information about the swift-evolution mailing list