[swift-evolution] [swift-evolution-announce] [Review] SE-0173: Add `MutableCollection.swap(_:with:)

Ben Cohen ben_cohen at apple.com
Thu Apr 27 10:27:35 CDT 2017


> On Apr 26, 2017, at 9:12 PM, John McCall via swift-evolution <swift-evolution at swift.org> wrote:
> 
>> 
>> Is that a mistake? Wouldn't the free function forward to the added method?
> 
> I'm not sure why this is there.  The implementation of the method is not part of the library specification.  If it forwards to the free function for some reason, it'll be via internal implementation details that certainly don't need to be described in this proposal.

It was there purely to explain why it was necessary to add an otherwise seemingly pointless method to MutableCollection. Needed because of https://bugs.swift.org/browse/SR-4660 <https://bugs.swift.org/browse/SR-4660> – in short, if you have a method on self, you cannot call the free function of the same name without full qualification, even if argument labels or different types make it clear which one was intended. So adding swap(_:with:) to MutableCollection would break code currently calling swap(&a,&b), which would need to change to Swift.swap(&a,&b). So we would have to put in an extra swap method on MutableCollection, that in turn calls Swift.swap, for source compatibility reasons.

However, if we adopt the preferred base name swapAt instead, this won’t be necessary.

(it will be necessary to add similar workarounds for min and max to String when it becomes a Collection, though...)


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170427/17647f91/attachment.html>


More information about the swift-evolution mailing list