[swift-evolution] [pitch] Adding in-place removeAll to the std lib

Richard Wei rxrwei at gmail.com
Sat Apr 8 20:56:52 CDT 2017

+1. We better make sure `equalTo:` is consistent with the label in the `Sequence.all` proposal.


> On Apr 8, 2017, at 19:41, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> wrote:
>> On Apr 8, 2017, at 12:44 PM, Xiaodi Wu via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> +1. Perfect. Let's not bikeshed this and get it done!
> Sorry, I'm going to have to insist on bikeshedding.
> `equalTo:` is kind of ugly and has no precedent in the standard library. Similar APIs seem to either leave the parameter unlabeled or use `of:` (as in `index(of:)`). I think unlabeled is probably the right answer here.
> The main shortcoming I can see is that if you see:
> 	array.removeAll(3)
> You might think `3` is either an index or a count. But neither of those actually make sense:
> * It can't be an index because then `All` would have no meaning. There's only ever one thing at a given index. Besides, indices are almost always marked with `at:` or another parameter label.
> * It can't be a count because `All` is already a count. What could "remove all 3" possibly mean if the array doesn't happen to have three elements?
> And this is only a problem if the value happens to be an integer. If it's anything else, the type makes clear that this can't possibly be an index or count; it must be an element.
> (But if you really do think this is insurmountable, `removeAll(of: 3)` *is* impossible to misinterpret and fits in better than `removeAll(equalTo:)`.)
> (P.S. The existing oddness of `removeFirst(_:)` compared to `removeFirst()` and `removeAll()` is why I proposed last year that it be renamed to `removePrefix(_:)`, which matches the count-taking `prefix(_:)` method.)
> --
> Brent Royal-Gordon
> Architechies
> _______________________________________________
> 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/20170408/c8ae276e/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 455 bytes
Desc: Message signed with OpenPGP
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170408/c8ae276e/attachment.sig>

More information about the swift-evolution mailing list