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

gadiraju praneeth praneethgadiraju at gmail.com
Wed Jun 8 10:10:19 CDT 2016


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 }

Is there a way currently where we can filter the array into two arrays
based on a condition?

If not how about something like a filterSplit function where we get a tuple
of values:

values.filterSplit { $0 % 2 == 0 } = ([2,4,6], [3,5,9])

I have implemented this in our project and wanted to get your thoughts on it
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160608/c9d8e90e/attachment.html>


More information about the swift-evolution mailing list