Re: [swift-evolution] Proposal: Filter split extension on Sequence to return tuple of sequences that meet criteria and that do not

2016-06-09 Thread plx via swift-evolution
This reminds me of something: I *very* often wish the standard library had an analog to `NSIndexSet`. I bring it up b/c it would allow, here, for IMHO a rather nice way to write the *eager* variant of this `filterSplit` (or preferably imho, `partition`, if not for the *other* `partition` out

Re: [swift-evolution] Proposal: Filter split extension on Sequence to return tuple of sequences that meet criteria and that do not

2016-06-09 Thread gadiraju praneeth via swift-evolution
Agree with the name. Also, the implementation could be better at Sequence level rather than specific to Array, just like filter On Wed, Jun 8, 2016 at 11:54 PM, Thorsten Seitz wrote: > +1 from me for adding this method to the standard library. > I would prefer the name

Re: [swift-evolution] Proposal: Filter split extension on Sequence to return tuple of sequences that meet criteria and that do not

2016-06-09 Thread Brent Royal-Gordon via swift-evolution
> Many times, I came across a scenario where I had to filter an array with a > condition and filter the same array with opposite of that condition. For > example: > > let values = [2, 4, 3, 5, 6, 9] > > let divisibleByTwo = values.filter { $0 % 2 == 0 } > let notDivisibleByTwo = values.filter

Re: [swift-evolution] Proposal: Filter split extension on Sequence to return tuple of sequences that meet criteria and that do not

2016-06-08 Thread Thorsten Seitz via swift-evolution
+1 from me for adding this method to the standard library. I would prefer the name `partition(by:)` for it, though, under which I know it from other languages and which is quite fitting, I think. -Thorsten > Am 08.06.2016 um 22:59 schrieb gadiraju praneeth via swift-evolution >

Re: [swift-evolution] Proposal: Filter split extension on Sequence to return tuple of sequences that meet criteria and that do not

2016-06-08 Thread gadiraju praneeth via swift-evolution
I implemented something similar with two filters initially, but because of 2N vs N I changed it On Wednesday, June 8, 2016, Dave Abrahams via swift-evolution < swift-evolution@swift.org> wrote: > > on Wed Jun 08 2016, Nate Cook wrote: > > >> On Jun 8, 2016, at 3:40 PM, Dave Abrahams via

Re: [swift-evolution] Proposal: Filter split extension on Sequence to return tuple of sequences that meet criteria and that do not

2016-06-08 Thread Dave Abrahams via swift-evolution
on Wed Jun 08 2016, Nate Cook wrote: >> On Jun 8, 2016, at 3:40 PM, Dave Abrahams via swift-evolution >> wrote: >> >> >> on Wed Jun 08 2016, Dave Abrahams wrote: >> > >>> on Wed Jun 08 2016, gadiraju praneeth

Re: [swift-evolution] Proposal: Filter split extension on Sequence to return tuple of sequences that meet criteria and that do not

2016-06-08 Thread Dave Abrahams via swift-evolution
on Wed Jun 08 2016, gadiraju praneeth wrote: > I added an extension to do this, something like this: > > extension Array { > > func filterSplit(includeElement: (Element) -> Bool) -> ([Element], > [Element]) { > > var elementsSatisfyingCondition = [Element]() > > var

Re: [swift-evolution] Proposal: Filter split extension on Sequence to return tuple of sequences that meet criteria and that do not

2016-06-08 Thread Nate Cook via swift-evolution
> On Jun 8, 2016, at 3:40 PM, Dave Abrahams via swift-evolution > wrote: > > > on Wed Jun 08 2016, Dave Abrahams wrote: > >> on Wed Jun 08 2016, gadiraju praneeth wrote: >> >>> Many times, I came across a

Re: [swift-evolution] Proposal: Filter split extension on Sequence to return tuple of sequences that meet criteria and that do not

2016-06-08 Thread gadiraju praneeth via swift-evolution
Its values.filterSplit { $0 % 2 == 0 } in this case On Wed, Jun 8, 2016 at 3:59 PM, gadiraju praneeth < praneethgadir...@gmail.com> wrote: > I added an extension to do this, something like this: > > extension Array { > > func filterSplit(includeElement: (Element) -> Bool) -> ([Element], >

Re: [swift-evolution] Proposal: Filter split extension on Sequence to return tuple of sequences that meet criteria and that do not

2016-06-08 Thread gadiraju praneeth via swift-evolution
I added an extension to do this, something like this: extension Array { func filterSplit(includeElement: (Element) -> Bool) -> ([Element], [Element]) { var elementsSatisfyingCondition = [Element]() var elementsNotSatisfyingCondition = [Element]() self.forEach {

Re: [swift-evolution] Proposal: Filter split extension on Sequence to return tuple of sequences that meet criteria and that do not

2016-06-08 Thread Dave Abrahams via swift-evolution
on Wed Jun 08 2016, Dave Abrahams wrote: > on Wed Jun 08 2016, gadiraju praneeth wrote: > >> Many times, I came across a scenario where I had to filter an array with a >> condition and filter the same array with opposite of that condition.

Re: [swift-evolution] Proposal: Filter split extension on Sequence to return tuple of sequences that meet criteria and that do not

2016-06-08 Thread Dave Abrahams via swift-evolution
on Wed Jun 08 2016, gadiraju praneeth wrote: > Many times, I came across a scenario where I had to filter an array with a > condition and filter the same array with opposite of that condition. For > example: > > let values = [2, 4, 3, 5, 6, 9] > > let divisibleByTwo =

[swift-evolution] Proposal: Filter split extension on Sequence to return tuple of sequences that meet criteria and that do not

2016-06-08 Thread gadiraju praneeth via swift-evolution
Many times, I came across a scenario where I had to filter an array with a condition and filter the same array with opposite of that condition. For example: let values = [2, 4, 3, 5, 6, 9] let divisibleByTwo = values.filter { $0 % 2 == 0 } let notDivisibleByTwo = values.filter { $0 % 2 != 0 }