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

Michael Ilseman milseman at apple.com
Tue Oct 17 15:27:31 CDT 2017


(I saw this after I sent my reply to Benjamin G). We can also deprecate it or warn when the type is concretely known to be Set. Not a total solution, but it’s nice to catch some bugs.

> On Oct 17, 2017, at 1:21 PM, Manolo van Ee <manolo.vanee at gmail.com> wrote:
> 
> 
> On Tue, 17 Oct 2017 at 21:00, Jonathan Hull via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
> 
>> On Oct 17, 2017, at 11:47 AM, Michael Ilseman via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> `==` conveys substitutability of the two Sequences. This does not necessarily entail anything about their elements, how those elements are ordered, etc., it just means two Sequences are substitutable. `elementsEqual` means that the two Sequences produce substitutable elements. These are different concepts and both are independently useful.
> 
> I agree that ‘==‘ conveys substitutability.  Here is the issue:
> 
> 	let a = Set([1,2,3,4,5])
> 	let b = Set([5,4,3,2,1])
> 
> 	a == b //True, they are substitutable
> 
> 	[1,2,3,4,5].elementsEqual(a) //True
> 	[1,2,3,4,5].elementsEqual(b) //False… I guess they weren’t actually substitutable after all
> 
> 
> Thanks,
> Jon
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> 
> I read along with most of the thread and like to add one thing. Maybe it’s not the right way to look at things, but I see protocol extensions as being part of any type that conforms to the protocol. As it is now, code completion on a Set will present me with the elementsEqual function, which in my view is misleading, since it cannot be used in any useful way with a Set.
> 
> By renaming elementsEqual we might be able to make it less misleading, but it will always be a useless function that is part of the Set namespace (or Dictionary for that matter).
> 
> I don’t know what the best solution would be, but to me it feels like distinguishing between Iterable and Sequence, or Ordered and Unordered makes sense, and it might be good to at least investigate what the impact would be.
> 
> Regards,
> /Manolo
> 
> 
> 
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171017/240972d4/attachment-0001.html>


More information about the swift-evolution mailing list