Skip to content
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 remove(where:) to RangeReplaceableCollection #11576

Merged
merged 1 commit into from
Apr 7, 2018

Conversation

airspeedswift
Copy link
Member

Initial implementation for swiftlang/swift-evolution#675

@airspeedswift
Copy link
Member Author

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - f3e48e4e72b64b41a89b9029abbc279a20aa39af

@airspeedswift
Copy link
Member Author

@swift-ci please test linux platform

@@ -509,6 +509,19 @@ public protocol RangeReplaceableCollection
///
/// - Complexity: O(*n*), where *n* is the length of the collection.
mutating func removeAll(keepingCapacity keepCapacity: Bool /*= false*/)

/// Removes all elements from the collection.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This summary seems to be wrong..

Given that the names in the proposal have been changed, and the intent behind having an implementation is that people can get actual experience with the proposal, I think this PR should be updated before we run the review.

/// Calling this method may invalidate any existing indices for use with this
/// collection.
///
/// - Parameter keepCapacity: Pass `true` to request that the collection
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This parameter doesn't seem to exist

@@ -1226,7 +1239,7 @@ extension RangeReplaceableCollection {
///
/// - Parameter isIncluded: A closure that takes an element of the
/// sequence as its argument and returns a Boolean value indicating
/// whether the element should be included in the returned array.
/// whether the element should be included in the returned collection.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to make that fix separately from this PR

extension RangeReplaceableCollection where Self: MutableCollection {
/// Removes from the collection all elements that satisfy the given predicate.
///
/// - Parameter where: A closure that takes an element of the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parameter name is predicate, not where, thank goodness!

@@ -0,0 +1,101 @@
//===--- Filter.swift - tests for lazy filtering --------------------------===//
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy/paste error?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

derp... thx

@airspeedswift airspeedswift changed the title Add removeAll(where:) to RangeReplaceableCollection Add remove(where:) to RangeReplaceableCollection Nov 16, 2017
@airspeedswift
Copy link
Member Author

@swift-ci please test

@martinr448
Copy link

I am not sure if it matters, but in remove(where:) the predicate is always evaluated twice for the first matching element, because the starting value for j is i, not its successor.

@airspeedswift
Copy link
Member Author

@martinr448 yeah, it also shouldn't use indices. I have been tinkering with this for a few different reasons including what the state should be if the predicate throws halfway, will push a new version soon.

@airspeedswift
Copy link
Member Author

@swift-ci please test and merge

@swift-ci swift-ci merged commit 3430f38 into swiftlang:master Apr 7, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants