-
Notifications
You must be signed in to change notification settings - Fork 446
Add trimmingSuffix
, trimmingPrefix
and mutating variants
#104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For what I understood from the issue we should also add an unconstrained version of trim
, right @timvermeulen ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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
@@ -48,6 +48,25 @@ func myAlgorithm2<Input>(input: Input) where Input: BidirectionalCollection { | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 allCollection
s andtrimmingSuffix(while:)
available only toBidirectionalCollection
s.This also adds a mutable variant of each
trim
method whereSubSequence == Self
.Detailed Design
The same applies to mutable
trim
s.String
must access mutabletrim
sDocumentation Plan
Docs not yet updated.
Test Plan
Since the two new methods are just a refactoring of
trimming
all those tests also apply to the new API.Source Impact
It doesn't break anything.
Checklist