-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[SR-1516][stdlib] Implement SE-0045 prefix(while:) and drop(while:) #3600
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
Conversation
public func drop( | ||
while predicate: @noescape (Iterator.Element) throws -> Bool | ||
) rethrows -> SubSequence { | ||
var start = startIndex |
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.
Mixed tabs and spaces
56e3c3d
to
8af6317
Compare
@gribozavr Still working on tests for the lazy wrappers but any issues with the current implementation? |
while predicate: @noescape (Iterator.Element) throws -> Bool | ||
) rethrows -> SubSequence { | ||
var start = startIndex | ||
while try start < endIndex && predicate(self[start]) { |
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.
start != endIndex
can be cheaper than <
. It is usually the same, but in some cases can be cheaper by a constant factor.
I need to do the drop wrapper. Nate is doing the lazy test coverage. Then we should be in good shape. |
@russbishop Thanks! |
@gribozavr I think we are done, subject to @natecook1000 's question about the |
Thanks! I haven't looked at the code yet, but let's get a CI run. @swift-ci Please test |
expectEqual(nil, iter1.next()) | ||
iter2 = iter1.base | ||
expectEqual(5, iter2.next()) | ||
} |
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.
My question from the other PR:
@gribozavr: If this is the result of providing a base property on LazyPrefixWhileIterator, does it make sense? It loses the first element that fails the predicate. I'm just not sure what the purpose is of having these base properties available—I used the other lazy iterators as a template for these, but I don't see a reason for including it.
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.
@natecook1000 @gribozavr Did we get a resolution on this? I think I agree with Nate that the base
property doesn't make sense in this context because we have no way to stuff the element back into the sequence.
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.
Dmitri is out. If you feel the base property can be elided and reintroduced later then please remove it. Else let me know and we can get this merged.
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.
@CodaFi I removed it. I'd rather be safe and not expose something with surprising behavior since we can always add it back in later.
@CodaFi All validation and unit tests pass. I'm just going to assume we missed the Swift 3 release train so this can go to |
Very nice! @swift-ci please smoke test OS X platform. |
@CodaFi any chance we can merge this? I don't want it to get stale again if we can help it! |
I'm concerned about @natecook1000's question. Was there ever a response? |
@russbishop Unless you see a reason to keep it, please remove the |
Includes lazy implementation courtesy of Nate Cook
@CodaFi Removed and pushed. Validation passed locally. |
@CodaFi This should be good |
So it is. Thank you for being patient @russbishop. |
Woot, congrats @russbishop |
@@ -200,6 +200,12 @@ internal class _AnyRandomAccessCollectionBox<Element> | |||
% end | |||
|
|||
% override = 'override' if Kind != 'Sequence' else '' | |||
internal ${override} func _drop( | |||
while predicate: (Element) throws -> Bool |
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.
All new predicates in this file should be @noescape
. Please also add dispatch tests in validation-test/stdlib/ExistentialCollection.swift.gyb
.
I will clean up this pull request in a subsequent patch @gribozavr. |
SE-0045 was implemented in swiftlang/swift#3600
Is this going to be included in Swift 3.0? If so, I think someone will need to cherry-pick it to |
Dmitri had reservations about its inclusion this late in the game. Besides, it is a purely additive component. |
In that case, perhaps we had better add a new section to the proposals page... ("Post-3.0"?) |
@jtbandes SE-0045 is also in the wrong section of the CHANGELOG.md. |
What's in this pull request?
Implementation for SE-0045 add
prefix(while:)
anddrop(while:)
.Resolved bug number: (SR-1516)
Before merging this pull request to apple/swift repository:
Triggering Swift CI
The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:
Smoke Testing
Validation Testing
Lint Testing
Note: Only members of the Apple organization can trigger swift-ci.