<div dir="ltr">Agree with the name. Also, the implementation could be better at Sequence level rather than specific to Array, just like filter</div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jun 8, 2016 at 11:54 PM, Thorsten Seitz <span dir="ltr">&lt;<a href="mailto:tseitz42@icloud.com" target="_blank">tseitz42@icloud.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div></div><div>+1 from me for adding this method to the standard library.</div><div>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.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>-Thorsten </div></font></span><div><div class="h5"><div><br>Am 08.06.2016 um 22:59 schrieb gadiraju praneeth via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;:<br><br></div><blockquote type="cite"><div><div dir="ltr">I added an extension to do this, something like this:<div><p style="color:rgb(0,0,0);margin:0px;font-size:13px;line-height:normal;font-family:Menlo">extension Array {</p><p style="color:rgb(0,0,0);margin:0px;font-size:13px;line-height:normal;font-family:Menlo">    func filterSplit(includeElement: (Element) -&gt; Bool) -&gt; ([Element], [Element]) {</p><p style="color:rgb(0,0,0);margin:0px;font-size:13px;line-height:normal;font-family:Menlo">        var elementsSatisfyingCondition = [Element]()</p><p style="color:rgb(0,0,0);margin:0px;font-size:13px;line-height:normal;font-family:Menlo">        var elementsNotSatisfyingCondition = [Element]()</p><p style="color:rgb(0,0,0);margin:0px;font-size:13px;line-height:normal;font-family:Menlo;min-height:15px">        </p><p style="color:rgb(0,0,0);margin:0px;font-size:13px;line-height:normal;font-family:Menlo">        self.forEach { element in</p><p style="color:rgb(0,0,0);margin:0px;font-size:13px;line-height:normal;font-family:Menlo">            if includeElement(element) { elementsSatisfyingCondition.append(element) }</p><p style="color:rgb(0,0,0);margin:0px;font-size:13px;line-height:normal;font-family:Menlo">            else { elementsNotSatisfyingCondition.append(element) }</p><p style="color:rgb(0,0,0);margin:0px;font-size:13px;line-height:normal;font-family:Menlo">        }</p><p style="color:rgb(0,0,0);margin:0px;font-size:13px;line-height:normal;font-family:Menlo;min-height:15px">        </p><p style="color:rgb(0,0,0);margin:0px;font-size:13px;line-height:normal;font-family:Menlo">        return (elementsSatisfyingCondition, elementsNotSatisfyingCondition)</p><p style="color:rgb(0,0,0);margin:0px;font-size:13px;line-height:normal;font-family:Menlo">    }</p><p style="color:rgb(0,0,0);margin:0px;font-size:13px;line-height:normal;font-family:Menlo">}</p><p style="color:rgb(0,0,0);margin:0px;font-size:13px;line-height:normal;font-family:Menlo"><br></p><p style="color:rgb(0,0,0);margin:0px;font-size:13px;line-height:normal;font-family:Menlo">that way you can right away do: values.filterSplit { &lt;yourPredicateBlock&gt; }</p><p style="color:rgb(0,0,0);margin:0px;font-size:13px;line-height:normal;font-family:Menlo"><br></p></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Jun 8, 2016 at 3:40 PM, Dave Abrahams via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span><br>
on Wed Jun 08 2016, Dave Abrahams &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br>
<br>
&gt; on Wed Jun 08 2016, gadiraju praneeth &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:<br>
&gt;<br>
&gt;&gt; Many times, I came across a scenario where I had to filter an array with a<br>
&gt;&gt; condition and filter the same array with opposite of that condition. For<br>
&gt;&gt; example:<br>
&gt;&gt;<br>
&gt;&gt; let values = [2, 4, 3, 5, 6, 9]<br>
&gt;&gt;<br>
&gt;&gt; let divisibleByTwo = values.filter { $0 % 2 == 0 }<br>
&gt;&gt; let notDivisibleByTwo = values.filter { $0 % 2 != 0 }<br>
&gt;&gt;<br>
&gt;&gt; Is there a way currently where we can filter the array into two arrays<br>
&gt;&gt; based on a condition?<br>
&gt;<br>
&gt; Well, you need a stable partition for this if you care about ordering<br>
&gt; (see<br>
&gt; <a href="https://github.com/apple/swift/blob/master/test/Prototypes/Algorithms.swift#L299" rel="noreferrer" target="_blank">https://github.com/apple/swift/blob/master/test/Prototypes/Algorithms.swift#L299</a>)<br>
&gt; but then you can do<br>
&gt;<br>
&gt; var parts = values<br>
&gt; let mid = values.stablePartition { $0 % 2 == 0 }<br>
&gt; let divisibleByTwo = parts.prefix(upTo: mid)<br>
&gt; let notDivisibleByTwo = parts.suffix(from: mid)<br>
&gt;<br>
&gt; Nate Cook has an enhancement to the result of stablyPartitioned in that<br>
&gt; prototype that would let you write:<br>
&gt;<br>
&gt;   let parts = values.stablyPartitioned { $0 % 2 == 0 }<br>
&gt;   let divisibleByTwo = parts.prefix(upTo: parts.partitionPoint)<br>
&gt;   let notDivisibleByTwo = parts.suffix(from: parts.partitionPoint)<br>
<br>
</span>Hmm, come to think of it, Nate, maybe there should also be a more<br>
convenient way to get the two partitions from the result.<br>
<div><div><br>
--<br>
Dave<br>
<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</div></div></blockquote></div><br></div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></div></div></div></blockquote></div><br></div>