[swift-dev] [Proposal] RangeReplaceableCollection should inherits from MutableCollection
frogcjn at 163.com
frogcjn at 163.com
Tue Dec 5 17:43:35 CST 2017
String should be some kind of MutableCollection. if we really want to restrict subscript of String should be { get } only, then we should consider make some extension methods of MutableCollection should available on SubrangeReplaceablecollection too.
For example:
>
> var c = [1, 2, 3, 4]
> print(c.reversed()) // OK
>
>
> var d = "1234"
> print(d.reversed()) // OK
They are both fine.
> var a = [1, 2, 3, 4]
> a.reverse()
> print(a) // OK
>
>
> var b = "1234"
> b.reverse() // no function
> print(b)
But this is weird.
String has String.reversed() function,
but it does not have String.reverse() function which is MutableCollection only.
I think, MutableCollection.reverse(), swapAt(_:_:), .partition(by:), sort(by:), should also be available with RangeReplaceableCollection.
> 在 2017年12月6日,06:55,Dave Abrahams <dabrahams at apple.com> 写道:
>
>
>
> Sent from my iPhone
>
>> On Dec 5, 2017, at 12:19 AM, Cao, Jiannan via swift-dev <swift-dev at swift.org> wrote:
>>
>>
>> But, I mean, what subscript (restrict to the length) could do is subset of p replaceSubrange could do, right?
>
> True but that would imply the opposite of the refinement relationship you’re suggesting. A derived protocol has to have a subset of the behavior of the protocol it refines.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-dev/attachments/20171206/03ee8ec1/attachment.html>
More information about the swift-dev
mailing list