Skip to content

Commit 32837b9

Browse files
benrimmingtonnatecook1000
authored andcommitted
Rename trimming(where:) to trimming(while:)
1 parent f91638b commit 32837b9

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

Guides/Trim.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
Returns a `SubSequence` formed by discarding all elements at the start and end of the collection
77
which satisfy the given predicate.
88

9-
This example uses `trimming(where:)` to get a substring without the white space at the beginning and end of the string.
9+
This example uses `trimming(while:)` to get a substring without the white space at the beginning and end of the string.
1010

1111
```swift
1212
let myString = " hello, world "
13-
print(myString.trimming(where: \.isWhitespace)) // "hello, world"
13+
print(myString.trimming(while: \.isWhitespace)) // "hello, world"
1414

15-
let results = [2, 10, 11, 15, 20, 21, 100].trimming(where: { $0.isMultiple(of: 2) })
15+
let results = [2, 10, 11, 15, 20, 21, 100].trimming(while: { $0.isMultiple(of: 2) })
1616
print(results) // [11, 15, 20, 21]
1717
```
1818

@@ -23,7 +23,7 @@ A new method is added to `BidirectionalCollection`:
2323
```swift
2424
extension BidirectionalCollection {
2525

26-
public func trimming(where predicate: (Element) throws -> Bool) rethrows -> SubSequence
26+
public func trimming(while predicate: (Element) throws -> Bool) rethrows -> SubSequence
2727
}
2828
```
2929

@@ -36,12 +36,12 @@ to add the `BidirectionalCollection` constraint will receive that inefficient im
3636
```swift
3737
func myAlgorithm<Input>(input: Input) where Input: Collection {
3838

39-
let trimmedInput = input.trimming(where: { ... }) // Uses least-efficient implementation.
39+
let trimmedInput = input.trimming(while: { ... }) // Uses least-efficient implementation.
4040
}
4141

4242
func myAlgorithm2<Input>(input: Input) where Input: BidirectionalCollection {
4343

44-
let trimmedInput = input.trimming(where: { ... }) // Uses most-efficient implementation.
44+
let trimmedInput = input.trimming(while: { ... }) // Uses most-efficient implementation.
4545
}
4646
```
4747

@@ -107,8 +107,8 @@ languages:
107107
```swift
108108
// Does `result` contain the input, trimmed of certain elements?
109109
// Or does this code mutate `input` in-place and return the elements which were dropped?
110-
let result = input.dropFromBothEnds(where: { ... })
110+
let result = input.dropFromBothEnds(while: { ... })
111111

112112
// No such ambiguity here.
113-
let result = input.trimming(where: { ... })
113+
let result = input.trimming(while: { ... })
114114
```

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Read more about the package, and the intent behind it, in the [announcement on s
3838
- [`chunked(by:)`, `chunked(on:)`, `chunks(ofCount:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/Chunked.md): Eager and lazy operations that break a collection into chunks based on either a binary predicate or when the result of a projection changes or chunks of a given count.
3939
- [`indexed()`](https://github.com/apple/swift-algorithms/blob/main/Guides/Indexed.md): Iterate over tuples of a collection's indices and elements.
4040
- [`interspersed(with:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/Interspersed.md): Place a value between every two elements of a sequence.
41-
- [`trimming(where:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/Trim.md): Returns a slice by trimming elements from a collection's start and end.
41+
- [`trimming(while:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/Trim.md): Returns a slice by trimming elements from a collection's start and end.
4242
- [`windows(ofCount:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/SlidingWindows.md): Breaks a collection into overlapping subsequences where elements are slices from the original collection.
4343
- [`striding(by:)`](https://github.com/apple/swift-algorithms/blob/main/Guides/Stride.md): Returns every nth element of a collection.
4444

Sources/Algorithms/Trim.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ extension BidirectionalCollection {
1313
/// Returns a `SubSequence` formed by discarding all elements at the start and
1414
/// end of the collection which satisfy the given predicate.
1515
///
16-
/// This example uses `trimming(where:)` to get a substring without the white
16+
/// This example uses `trimming(while:)` to get a substring without the white
1717
/// space at the beginning and end of the string:
1818
///
1919
/// let myString = " hello, world "
20-
/// print(myString.trimming(where: \.isWhitespace)) // "hello, world"
20+
/// print(myString.trimming(while: \.isWhitespace)) // "hello, world"
2121
///
2222
/// - Parameters:
2323
/// - predicate: A closure which determines if the element should be
@@ -27,7 +27,7 @@ extension BidirectionalCollection {
2727
///
2828
@inlinable
2929
public func trimming(
30-
where predicate: (Element) throws -> Bool
30+
while predicate: (Element) throws -> Bool
3131
) rethrows -> SubSequence {
3232
// Consume elements from the front.
3333
let sliceStart = try firstIndex { try predicate($0) == false } ?? endIndex

0 commit comments

Comments
 (0)