Re: [swift-evolution] Additional methods for removing elements from a collection in Swift

2017-09-27 Thread Ben Cohen via swift-evolution
> On Sep 27, 2017, at 12:44 PM, Tony Allevato wrote: > > > > On Wed, Sep 27, 2017 at 10:36 AM Ben Cohen via swift-evolution > > wrote: > > >> On Sep 25, 2017, at 2:12 AM, Alwyn Concessao via

Re: [swift-evolution] Additional methods for removing elements from a collection in Swift

2017-09-27 Thread Tony Allevato via swift-evolution
On Wed, Sep 27, 2017 at 10:36 AM Ben Cohen via swift-evolution < swift-evolution@swift.org> wrote: > > > On Sep 25, 2017, at 2:12 AM, Alwyn Concessao via swift-evolution < > swift-evolution@swift.org> wrote: > > mutating func removeElementInSubrange(_ elementToBeRemoved:Element,in > range:Range){

Re: [swift-evolution] Additional methods for removing elements from a collection in Swift

2017-09-27 Thread Ben Cohen via swift-evolution
> On Sep 25, 2017, at 2:12 AM, Alwyn Concessao via swift-evolution > wrote: > > mutating func removeElementInSubrange(_ elementToBeRemoved:Element,in > range:Range){ > > //check if elementoBeRemoved exists; if yes, check if the index of > elementToBeRemoved is

Re: [swift-evolution] Additional methods for removing elements from a collection in Swift

2017-09-26 Thread Saagar Jha via swift-evolution
Sent from my iPhone > On Sep 25, 2017, at 22:16, Jonathan Hull via swift-evolution > wrote: > > As he says, it is an in-place equivalent of filter, so the use-cases would be > similar. I could see this being extremely useful. Off the top of my head: > >

Re: [swift-evolution] Additional methods for removing elements from a collection in Swift

2017-09-26 Thread Ben Cohen via swift-evolution
> On Sep 26, 2017, at 2:59 AM, Xiaodi Wu via swift-evolution > wrote: > > On Tue, Sep 26, 2017 at 00:15 Jonathan Hull > wrote: > As he says, it is an in-place equivalent of filter, so the use-cases would be > similar. I

Re: [swift-evolution] Additional methods for removing elements from a collection in Swift

2017-09-26 Thread Alwyn Concessao via swift-evolution
Considering some of the suggestions which have come up here I'm glad to say that I have been able to achieve the in-place filter and remove(where:) functionalities by using existing APIs. Alwyn On Tuesday, 26 September 2017, 4:47:48 PM IST, Karl Wagner wrote:

Re: [swift-evolution] Additional methods for removing elements from a collection in Swift

2017-09-26 Thread Karl Wagner via swift-evolution
Yeah, IMO it’s fair to add this function. I also think we should have a way of removing elements at multiple indexes (e.g. from a generic sequence of indexes). That’s something that naïve programmers are more likely to get wrong. - Karl > On 26. Sep 2017, at 06:27, Félix Cloutier via

Re: [swift-evolution] Additional methods for removing elements from a collection in Swift

2017-09-26 Thread Xiaodi Wu via swift-evolution
That is very nice. Unless someone can show how this can be easily achieved in an ergonomic way with today’s APIs, I am on board with remove(where:). On Tue, Sep 26, 2017 at 05:28 Jonathan Hull wrote: > Alwyn just pointed out another use-case as well. > > If there is either a

Re: [swift-evolution] Additional methods for removing elements from a collection in Swift

2017-09-26 Thread Jonathan Hull via swift-evolution
Alwyn just pointed out another use-case as well. If there is either a @discardableResult or two variants (one which returns a result) where the method returns the items being removed (which is to be expected of a method named “remove”), then it becomes useful in ways which filter alone is not.

Re: [swift-evolution] Additional methods for removing elements from a collection in Swift

2017-09-26 Thread Jonathan Hull via swift-evolution
> On Sep 26, 2017, at 2:37 AM, Alwyn Concessao wrote: > > @Jonathan Hull - You've mentioned about splitting a list using a filter > which returns the filtered list and the remainder.Is it similar to having a > filter function which does the filtering on the original

Re: [swift-evolution] Additional methods for removing elements from a collection in Swift

2017-09-26 Thread Xiaodi Wu via swift-evolution
On Tue, Sep 26, 2017 at 00:15 Jonathan Hull wrote: > As he says, it is an in-place equivalent of filter, so the use-cases would > be similar. I could see this being extremely useful. Off the top of my > head: > > views.remove(where: {$0.isHidden}) //Remove all views which are

Re: [swift-evolution] Additional methods for removing elements from a collection in Swift

2017-09-26 Thread Alwyn Concessao via swift-evolution
First of all thanks to you all for the suggestions/thoughts on this idea. @Jonathan Hull - You've mentioned  about splitting a list using a filter which returns the filtered list and the remainder.Is it similar to having a filter function which does the filtering on the original collection and

Re: [swift-evolution] Additional methods for removing elements from a collection in Swift

2017-09-26 Thread Félix Cloutier via swift-evolution
Same as `filter`, but in-place. We thought that `sorted` deserved an in-place version; that +(Array, Array) deserved an in-place version (append(contentsOf:)); there are parallels to be made between `dropFirst` and `removeFirst`; we have index and formIndex. There's a ton more, Swift loves to

Re: [swift-evolution] Additional methods for removing elements from a collection in Swift

2017-09-25 Thread Jonathan Hull via swift-evolution
As he says, it is an in-place equivalent of filter, so the use-cases would be similar. I could see this being extremely useful. Off the top of my head: views.remove(where: {$0.isHidden}) //Remove all views which are hidden from the list. Another thing which seems to be missing

Re: [swift-evolution] Additional methods for removing elements from a collection in Swift

2017-09-25 Thread Xiaodi Wu via swift-evolution
What is the use case? On Mon, Sep 25, 2017 at 23:27 Félix Cloutier wrote: > Actually, IMO, it's an oversight that there's no remove(where:), or > another in-place equivalent to `filter`. I'm in favor of it. > > Félix > > > Le 25 sept. 2017 à 15:17, Xiaodi Wu

Re: [swift-evolution] Additional methods for removing elements from a collection in Swift

2017-09-25 Thread Félix Cloutier via swift-evolution
Actually, IMO, it's an oversight that there's no remove(where:), or another in-place equivalent to `filter`. I'm in favor of it. Félix > Le 25 sept. 2017 à 15:17, Xiaodi Wu a écrit : > > On Mon, Sep 25, 2017 at 4:55 PM, Xiaodi Wu

Re: [swift-evolution] Additional methods for removing elements from a collection in Swift

2017-09-25 Thread Xiaodi Wu via swift-evolution
On Mon, Sep 25, 2017 at 4:55 PM, Xiaodi Wu wrote: > Brent has a great proposal in the pipeline regularizing the names of some > of these functions and filling in some of the more glaring gaps. > > With regard to the specific items proposed here, Felix shows that ‘filter’ >

Re: [swift-evolution] Additional methods for removing elements from a collection in Swift

2017-09-25 Thread Xiaodi Wu via swift-evolution
Brent has a great proposal in the pipeline regularizing the names of some of these functions and filling in some of the more glaring gaps. With regard to the specific items proposed here, Felix shows that ‘filter’ provides an idiomatic one-line way of doing some of what is proposed; currently

Re: [swift-evolution] Additional methods for removing elements from a collection in Swift

2017-09-25 Thread Félix Cloutier via swift-evolution
Another alternative is to use `array = array.filter { $0 != someElement }`. I thought that there would be a `remove(where:)` method, but there isn't. Félix > Le 25 sept. 2017 à 02:12, Alwyn Concessao via swift-evolution > a écrit : > > Hello, > > After going

[swift-evolution] Additional methods for removing elements from a collection in Swift

2017-09-25 Thread Alwyn Concessao via swift-evolution
Hello, After going through the Swift standard library functions provided for removing elements from a collection, one common pattern can be observed in all those functions and that is the functions provide to remove elements from the collection by passing the position or index of the element or