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
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
> 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
+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
>
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
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
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
> 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
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],
>
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 {
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.
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 =
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 }
13 matches
Mail list logo