[swift-evolution] [Pitch] Retiring `where` from for-in loops

Charlie Monroe charlie at charliemonroe.net
Fri Jun 10 00:04:24 CDT 2016


> On Jun 9, 2016, at 7:15 PM, Erica Sadun via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
>> On Jun 8, 2016, at 10:17 PM, Sean Heber <sean at fifthace.com <mailto:sean at fifthace.com>> wrote:
>> 
>> 
>> On Jun 8, 2016, at 10:51 PM, Erica Sadun via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>> I saw your post on that *after* I finished sending this. Moving `where` next to the pattern, like you'd find in `catch` and switch `case`, the code would look like this:
>>> 
>>> for i where i % 2 == 0 in sequence {
>>>     // do stuff
>>> }
>> 
>> This is the best version yet - the placement of 'where' makes total sense and I really like it there.
>> 
> 
> I really like how it aligns with case statements better. BUT I think using guard is still better because 
> there's still user confusion between "does this terminate" and "does this filter".
> 
> Guard use is unambiguous.

It may seem superfluous, but what about something like

for i in sequence where i % 2 == 0 else continue {
	/// do stuff
}

for i in sequence where i % 2 == 0 else break {
	/// do stuff
}

Which would make it explicit whether the for-loop should filter or break, yet it's still a one-liner...



> 
> -- E
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160610/de249721/attachment.html>


More information about the swift-evolution mailing list