[swift-evolution] Using "where" to filter an array
Charles Constant
charles at charlesism.com
Sat Dec 19 22:22:22 CST 2015
Thanks Charles ,
I know it's possible to do the same thing with filter. The syntax I drew
attention to would be an alternate way.
My only rationale is that, if it works in one place, it ought to work
everywhere. The redundancy bothers me too, but since the concept exists, we
may as well allow it everywhere. Otherwise, it's still redundant in a "for"
loop (maybe performance is better, but that could be optimized?), but also
inconsistent because it seems intuitively like it ought to create a subset
whereas in reality it is illegal.
Does it bother anyone else, or am I nitpicking?
On Sat, Dec 19, 2015 at 7:52 PM, Charles Srstka <cocoadev at charlessoft.com>
wrote:
> On Dec 19, 2015, at 9:43 PM, Charles Constant via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>
> I noticed several weeks ago that the following is illegal:
>
> let new_arr = el in arr where el.is_foo // illegal
>
> I assumed it would work because it's consistent with the filtering that
> exists in a "for" loop, i.e.:
>
> for el in arr where el.is_foo // legal
>
> Is this "new proposal" material? I thought I would check in case it's
> already on the roadmap, or inherently wrong.
>
>
> I believe what you want is already possible via the “filter” method.
>
> Charles
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151219/9c9ce357/attachment.html>
More information about the swift-evolution
mailing list