Re: [swift-evolution] [draft] Add last(where:) and lastIndex(where:) Methods

2017-11-27 Thread Adrian Zubarev via swift-evolution
dex(of:) but starting from end Introduction The standard library should include methods for finding the last element in a sequence, and the index of the last element in a collection, that match a given predicate. Swift-evolution thread: [swift-evolution] (Draft) Add last(where:) and lastIndex(wh

[swift-evolution] [draft] Add last(where:) and lastIndex(where:) Methods

2017-11-27 Thread Nate Cook via swift-evolution
ard library should include methods for finding the last element in a sequence, and the index of the last element in a collection, that match a given predicate. Swift-evolution thread: [swift-evolution] (Draft) Add last(where:) and lastIndex(where:) methods <https://lists.swift.org/pipermail

Re: [swift-evolution] (Draft) Add last(where:) and lastIndex(where:) methods

2016-05-21 Thread Brent Royal-Gordon via swift-evolution
>> Similarly, we shouldn't provide operations which are going to >> repeatedly seek elements near the tail of the list unless we're using >> a type which can access that tail efficiently. `last` is one >> thing—it's only O(N). `lastIndex(of:)` is, I believe, O(n log n) in >> the case of an element

Re: [swift-evolution] (Draft) Add last(where:) and lastIndex(where:) methods

2016-05-20 Thread Dave Abrahams via swift-evolution
on Thu May 19 2016, Brent Royal-Gordon wrote: >> Why shouldn't this work with all Collections, with an optimized version >> for BidirectionalCollections? > > Why don't we have `index(before:)` on non-BidirectionalCollections? It's not > that you can't write it: > > func index(before

Re: [swift-evolution] (Draft) Add last(where:) and lastIndex(where:) methods

2016-05-19 Thread Dave Abrahams via swift-evolution
on Tue May 10 2016, Nate Cook wrote: > I've needed these in the past and used them in other languages—any feedback > on this idea? > > - > > Add

Re: [swift-evolution] (Draft) Add last(where:) and lastIndex(where:) methods

2016-05-11 Thread Nate Cook via swift-evolution
> On May 11, 2016, at 12:32 PM, Hooman Mehr via swift-evolution > wrote: > > Thank you for your comments. > > I think additional index manipulation and collection scanning API is needed, > and your proposal cover an important part of it. > > I also have some

Re: [swift-evolution] (Draft) Add last(where:) and lastIndex(where:) methods

2016-05-11 Thread Hooman Mehr via swift-evolution
Thank you for your comments. I think additional index manipulation and collection scanning API is needed, and your proposal cover an important part of it. I also have some clarifications and comments inline: > On May 10, 2016, at 4:52 PM, Nate Cook wrote: > Thanks Hooman!

Re: [swift-evolution] (Draft) Add last(where:) and lastIndex(where:) methods

2016-05-10 Thread Nate Cook via swift-evolution
> On May 10, 2016, at 7:27 PM, plx via swift-evolution > wrote: > > Do these return endIndex or nil on a not-found? > > Either can work with different tradeoffs; depends on what you care > about...but the choice should be justified and the alternative explained.

Re: [swift-evolution] (Draft) Add last(where:) and lastIndex(where:) methods

2016-05-10 Thread plx via swift-evolution
Do these return endIndex or nil on a not-found? Either can work with different tradeoffs; depends on what you care about...but the choice should be justified and the alternative explained. > On May 10, 2016, at 13:54, Nate Cook via swift-evolution > wrote: > > I've

Re: [swift-evolution] (Draft) Add last(where:) and lastIndex(where:) methods

2016-05-10 Thread Nate Cook via swift-evolution
Thanks Hooman! Those do look like useful extensions. I think the proposal should stay focused on the APIs it includes already. > On May 10, 2016, at 4:18 PM, Hooman Mehr wrote: > > I agree with adding more such API’s. > > Look at this gist >

Re: [swift-evolution] (Draft) Add last(where:) and lastIndex(where:) methods

2016-05-10 Thread Xiaodi Wu via swift-evolution
If these are to be added, I'd advocate for renaming `index(of:)` and `index(where:)` to `firstIndex(of:)` and `firstIndex(where:)`, respectively. On Tue, May 10, 2016 at 13:54 Nate Cook via swift-evolution < swift-evolution@swift.org> wrote: > I've needed these in the past and used them in other

Re: [swift-evolution] (Draft) Add last(where:) and lastIndex(where:) methods

2016-05-10 Thread Hooman Mehr via swift-evolution
I agree with adding more such API’s. Look at this gist for an implementation of a few more of what I find useful. You can add them to your proposal if you like them and I will be able to help better shape it up. Here is a

[swift-evolution] (Draft) Add last(where:) and lastIndex(where:) methods

2016-05-10 Thread Nate Cook via swift-evolution
I've needed these in the past and used them in other languages—any feedback on this idea? Add last(where:) and lastIndex(where:) Methods to Bidirectional Collections The standard library should include methods for finding the last element of a bidirectional collection that matches a predicate,