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

Brent Royal-Gordon brent at architechies.com
Sat Apr 8 19:41:42 CDT 2017

> On Apr 8, 2017, at 12:44 PM, Xiaodi Wu via swift-evolution <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:


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170408/845e68af/attachment.html>

More information about the swift-evolution mailing list