[swift-evolution] Adding a new filter method which returns 2 arrays

Jeremy Pereira jeremy.j.pereira at googlemail.com
Mon Jan 18 05:55:02 CST 2016


> On 17 Jan 2016, at 05:55, Arman Shan via swift-evolution <swift-evolution at swift.org> wrote:
> 
> The dictionary return will be a more complicated version of the partition method. The reason I thought the partition method would be a trivial addition to the stdlib is because filter pretty much does all that work; it just doesn’t return the “other” items. so this function would be sort of a “filter2”.

I think the point of the dictionary return is that it gives you a generalised version of partition (why would you only ever want to partition a set into only two subsets?). The naive implementation is not *very* complicated. I just wrote it in about five minutes. It lets you do some interesting things, but whether it is worth having in the standard library is for others to decide.


> 
> 
> 
>> On Jan 16, 2016, at 7:46 AM, Tino Heth <2th at gmx.de> wrote:
>> 
>> I would prefer a more general approach:
>> Return value could be a dictionary whose values are arrays, and the supplied function could by anything that maps target contents to possible keys (Bool would be possible, but also attributes like "lastName", "age"…).
>> But it isn't that hard to write this on your own, so I'm not sure if it's fundamental enough for stdlib...
>> 
>> Tino
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list