Skip to content

Commit b0df1ff

Browse files
committed
Accept SE-0197 with revisions.
1 parent 15539d5 commit b0df1ff

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

proposals/0197-remove-where.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
# Adding in-place `remove(where:)` to the Standard Library
1+
# Adding in-place `removeAll(where:)` to the Standard Library
22

33
* Proposal: [SE-0197](0197-remove-where.md)
44
* Author: [Ben Cohen](https://github.com/airspeedswift)
55
* Review Manager: [John McCall](https://github.com/rjmccall)
6-
* Status: **Active review (January 25...30)**
6+
* Status: **Accepted with Revisions**
77
* Implementation: [apple/swift#11576](https://github.com/apple/swift/pull/11576)
8+
* Review: [Thread](https://forums.swift.org/t/se-0197-add-in-place-remove-where/8872)
9+
* Previous Revision: [1](https://github.com/apple/swift-evolution/blob/feec7890d6c193e9260ac9905456f25ef5656acd/proposals/0197-remove-where.md)
810

911
## Introduction
1012

1113
It is common to want to remove all occurrences of a certain element from a
12-
collection. This proposal is to add a `remove` algorithm to the
14+
collection. This proposal is to add a `removeAll` algorithm to the
1315
standard library, which will remove all entries in a collection in-place
1416
matching a given predicate.
1517

@@ -65,7 +67,7 @@ important example of this, because its elements (graphemes) are variable width.
6567
Add the following method to `RangeReplaceableCollection`:
6668

6769
```swift
68-
nums.remove(where: isOdd)
70+
nums.removeAll(where: isOdd)
6971
```
7072

7173
The default implementation will use the protocol's `init()` and `append(_:)`
@@ -90,11 +92,11 @@ Add the following to `RangeReplaceableCollection`:
9092
```swift
9193
protocol RangeReplaceableCollection {
9294
/// Removes every element satisfying the given predicate from the collection.
93-
mutating func remove(where: (Iterator.Element) throws -> Bool) rethrows
95+
mutating func removeAll(where: (Iterator.Element) throws -> Bool) rethrows
9496
}
9597

9698
extension RangeReplaceableCollection {
97-
mutating func remove(where: (Iterator.Element) throws -> Bool) rethrows {
99+
mutating func removeAll(where: (Iterator.Element) throws -> Bool) rethrows {
98100
// default implementation similar to self = self.filter
99101
}
100102
}
@@ -119,7 +121,7 @@ This change is purely additive so has no API resilience consequences.
119121

120122
## Alternatives considered
121123

122-
`remove(where:)` takes a closure with `true` for elements to remove.
124+
`removeAll(where:)` takes a closure with `true` for elements to remove.
123125
`filter` takes a closure with elements to keep. In both cases, `true` is the
124126
"active" case, so likely to be what the user wants without having to apply a
125127
negation. The naming of `filter` is unfortunately ambiguous as to whether it's
@@ -131,3 +133,8 @@ have an equivalent for collections of `Equatable` elements. A similar addition
131133
could be made that removes every element equal to a given value. This could
132134
easily be done as a further additive proposal later.
133135

136+
The initial proposal of this feature named it `remove(where:)`. During review,
137+
it was agreed that this was unnecessarily ambiguous about whether all the
138+
matching elements should be removed or just the first, and so the method was
139+
renamed to `removeAll(where:)`.
140+

0 commit comments

Comments
 (0)