Add trimmingSuffix, trimmingPrefix and mutating variants#104
Conversation
|
|
||
| extension BidirectionalCollection where Self == SubSequence { | ||
| @inlinable | ||
| public mutating func trim( |
There was a problem hiding this comment.
For what I understood from the issue we should also add an unconstrained version of trim, right @timvermeulen ?
natecook1000
left a comment
There was a problem hiding this comment.
Thanks for this, @fedeci! 👏
I have a few notes for you below, and we also need a couple overloads for each of the mutating methods. The current ones are available for RangeReplaceableCollection types; we can also do these operations on self-slicing types (e.g. where Self == Self.SubSequence). One such type is a Range<Int> — when you write (0..<10).dropFirst(3) you end up with the range 3..<10. Unfortunately, there are also self-slicing, range-replaceable types (like Substring and ArraySlice), so we'll also need overloads that have both constraints.
|
Do |
natecook1000
left a comment
There was a problem hiding this comment.
@fedeci Looking good! A few notes below and then we can merge this addition.
|
Are still missing documents in the |
|
@fedeci This looks ready to go! Would you like to add a skeleton guide and mark this as ready for review? |
|
Sure, just give me a couple of days because I am full of exams in this period. edit: weeks probably. Sorry :( |
|
@swift-ci Please test |
|
Here it is :) |
ee65d3b to
46b11ba
Compare
46b11ba to
8a67ef3
Compare
| Swift provides the `BidirectionalCollection` protocol for marking types which support reverse traversal, | ||
| and generic types and algorithms which want to make use of that should add it to their constraints. | ||
|
|
||
| ### >= 0.3.0 |
There was a problem hiding this comment.
I added 0.3.0 supposing that this will be released in a next minor version, but I am not sure.
|
@swift-ci Please test |
|
🎉 |
Add `trimmingSuffix`, `trimmingPrefix` and mutating variants (apple#104)
Description
Closes #101
trimming(while:)is split in two methodstrimmingPrefix(while:)which is available to allCollections andtrimmingSuffix(while:)available only toBidirectionalCollections.This also adds a mutable variant of each
trimmethod whereSubSequence == Self.Detailed Design
The same applies to mutable
trims.Stringmust access mutabletrimsDocumentation Plan
Docs not yet updated.
Test Plan
Since the two new methods are just a refactoring of
trimmingall those tests also apply to the new API.Source Impact
It doesn't break anything.
Checklist