Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 46b11ba

Browse files
committedMay 21, 2021
Update Guides
1 parent 18406a2 commit 46b11ba

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed
 

‎Guides/Trim.md

+20-1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,25 @@ func myAlgorithm2<Input>(input: Input) where Input: BidirectionalCollection {
4848
Swift provides the `BidirectionalCollection` protocol for marking types which support reverse traversal,
4949
and generic types and algorithms which want to make use of that should add it to their constraints.
5050

51+
### >= 0.3.0
52+
53+
In `v0.4.0` new methods are added to allow discarding all the elements matching the predicate at the beginning (prefix) or at the ending (suffix) of the collection.
54+
- `trimmingSuffix(while:)` can only be run on collections conforming to the `BidirectionalCollection` protocol.
55+
- `trimmingPrefix(while:)` can be run also on collections conforming to the `Collection` protocol.
56+
57+
```swift
58+
let myString = " hello, world "
59+
print(myString.trimmingPrefix(while: \.isWhitespace)) // "hello, world "
60+
61+
print(myString.trimmingSuffix(while: \.isWhitespace)) // " hello, world"
62+
```
63+
Also mutating variants for all the methods already existing and the new ones are added.
64+
```swift
65+
var myString = " hello, world "
66+
myString.trim(while: \.isWhitespace)
67+
print(myString) // "hello, world"
68+
```
69+
5170
### Complexity
5271

5372
Calling this method is O(_n_).
@@ -111,4 +130,4 @@ let result = input.dropFromBothEnds(while: { ... })
111130

112131
// No such ambiguity here.
113132
let result = input.trimming(while: { ... })
114-
```
133+
```

0 commit comments

Comments
 (0)
Please sign in to comment.