Skip to content

[Proposal] Add last(where:), lastIndex(where:), and lastIndex(of:) methods#773

Merged
rjmccall merged 3 commits intoswiftlang:masterfrom
natecook1000:nc-last-methods
Mar 29, 2018
Merged

[Proposal] Add last(where:), lastIndex(where:), and lastIndex(of:) methods#773
rjmccall merged 3 commits intoswiftlang:masterfrom
natecook1000:nc-last-methods

Conversation

@natecook1000
Copy link
Member

No description provided.

@amosavian
Copy link

It's awesome. However I prefer a options argument rather than new methods. Something like:

array.index(of: 10, options: .backward)

@fnoyanisi
Copy link

I think the fact the proposal does not break current ABI / API and provides great flexibility, implementing new methods sounds like a better idea to me than modifying or adding functionality to existing ones.

@amosavian
Copy link

amosavian commented Dec 13, 2017

Neither API nor ABI are not stabilized yet. It's better to discuss about which is more preferable rather than which one won't break api.

I've said I prefer less functions with arguments (with default value of course!) rather than a few dozen of similar functions which do fundamentally the same thing in different manner.

@natecook1000
Copy link
Member Author

@amosavian Thanks for that feedback! I added your suggestion to the "alternatives considered" section, so people should see it when the proposal eventually goes under review.

a.index(of: 10, options: .backwards) // 6
```

This alternative approach matches the convention used in Foundation, such as `NSString.range(of:options:)` and `NSArray.indexOfObject(options:passingTest:)`, but in the opinion of this author, separate functions better suit the structure of the Swift standard library.
Copy link
Member

Choose a reason for hiding this comment

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

Parameterizing the direction is also a compile-time and run-time pessimisation.

@rjmccall rjmccall merged commit c07e3e7 into swiftlang:master Mar 29, 2018
rjmccall added a commit that referenced this pull request Mar 29, 2018
@rjmccall
Copy link
Contributor

This is now SE-0204.

@natecook1000 natecook1000 deleted the nc-last-methods branch April 22, 2022 19:04
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.

5 participants