Skip to content

More updates for algorithms proposal #324

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

Merged
merged 6 commits into from
Apr 23, 2022

Conversation

natecook1000
Copy link
Member

This updates the Sequence/Collection constraints for several methods' parameters, adds missing parameters to the two split variations, and adopts opaque parameter types where allowed today.

Copy link
Member

@milseman milseman left a comment

Choose a reason for hiding this comment

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

This LGTM, but want to make sure @itingliu can take a look.

Can you follow up with making sure the implementation matches?

@@ -234,7 +234,7 @@ extension Collection where Element: Equatable {
/// - Parameter other: A sequence to search for within this collection.
/// - Returns: `true` if the collection contains the specified sequence,
/// otherwise `false`.
public func contains<S: Sequence>(_ other: S) -> Bool
public func contains<C: Collection>(_ other: C) -> Bool
Copy link
Member

Choose a reason for hiding this comment

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

Would this be some Collection<Element>?

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, all of the sequence/collection parameters can change to that. Where there's still a <R: RegexComponent> parameter, it's because we need the component's output parameter. Those will change to e.g. func firstMatch<Output>(of regex: some RegexComponent<Output>) -> Regex<Output>.Match? when we have the primary associated type.

Copy link
Member

Choose a reason for hiding this comment

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

Is the primary associate type tracked anywhere? Do we know when we need to integrate that?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's waiting on stdlib's adoption of lightweight generics. Filed #325 to track this

Copy link
Member Author

Choose a reason for hiding this comment

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

And the RegexComponent primary associated type is here: #207


/// Match part of the regex, starting at the beginning.
/// - Parameter r: The regex to match against.
/// - Returns: The match if there is one, or `nil` if none.
public func prefixMatch<R: RegexComponent>(of r: R) -> Regex<R.Output>.Match?
public func prefixMatch<R: RegexComponent>(of regex: R) -> Regex<R.RegexOutput>.Match?
Copy link
Member

Choose a reason for hiding this comment

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

Update the doc comment for r to be regex.

@@ -234,7 +234,7 @@ extension Collection where Element: Equatable {
/// - Parameter other: A sequence to search for within this collection.
/// - Returns: `true` if the collection contains the specified sequence,
/// otherwise `false`.
public func contains<S: Sequence>(_ other: S) -> Bool
public func contains<C: Collection>(_ other: C) -> Bool
Copy link
Contributor

Choose a reason for hiding this comment

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

It's waiting on stdlib's adoption of lightweight generics. Filed #325 to track this

public func split<R: RegexComponent>(by separator: R) -> some Collection<Substring>
/// elements.
public func split(
by separator: some RegexComponent,
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to drop by and call it

public func split(separator... 

That would match the existing String.split

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm a little nervous about some of the overloads we already have in the stdlib — let me take a quick look.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, this should be safe — when someone has a type-unconstrained function reference, they'll still get the current split(separator:maxSplits:omittingEmptySubsequences:) method, because it's more tightly specified (i.e., to Character, instead of a generic collection). I don't think adopting the lightweight generics syntax will change the story here.

Copy link
Member

Choose a reason for hiding this comment

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

Even if this is from _StringProcessing instead of Swift?

Copy link
Member Author

Choose a reason for hiding this comment

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

@itingliu
Copy link
Contributor

@swift-ci please test

@itingliu itingliu merged commit 571e259 into swiftlang:main Apr 23, 2022
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.

3 participants