<div dir="ltr">> the second clause can depend on the first...<div><br><div>For those cases, I'd really prefer plain dumb old for loop on two separate visually distinct lines :)</div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Dec 10, 2015 at 12:13 AM, Chris Eidhof via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Yes, it’d be great if you can combine it with where. Alternatively, it could be interesting to instead explore array comprehension syntax, rather than making `for` smarter. That’d allow for a more functional style. For example, Norvig’s spelling corrector (<a href="http://norvig.com/spell-correct.html" target="_blank">http://norvig.com/spell-correct.html</a>) would then be very straightforward to port.<div><br></div><div>Re the x operator: it’s even easier if you define it with flatMap. However, the for syntax is different, because the second clause can depend on the first...<br><div><br></div><div>Chris<div><div class="h5"><br><div><br><div><blockquote type="cite"><div>On 09 Dec 2015, at 15:48, Jacob Bandes-Storch <<a href="mailto:jtbandes@gmail.com" target="_blank">jtbandes@gmail.com</a>> wrote:</div><br><div>Are you expecting that this could be combined with "where" clauses?<br><br>for x in range1 where x%2==0, y in range2 where y%3==0 {}<br><br>for x in range1, y in range2 where x%2==0 && y%3==0 {}<br><br>I think it's a good idea, but the implications may be less than obvious.<br><div class="gmail_quote"><div dir="ltr">On Wed, Dec 9, 2015 at 12:37 PM <a href="mailto:krzysztof@siejkowski.net" target="_blank">krzysztof@siejkowski.net</a> via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">+1. Way more readable than nested loops and consistent with already existing syntax.<br>
<br>
<br>
-----Original Message-----<br>
From: Chris Eidhof via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>><br>
Reply: Chris Eidhof <<a href="mailto:chris@eidhof.nl" target="_blank">chris@eidhof.nl</a>><br>
Date: December 9, 2015 at 9:00:26 PM<br>
To: <a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a> <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>><br>
Subject: [swift-evolution] Extending the for loop to have multiple clauses<br>
<br>
> I think it could be really nice to extend the for-loop so that it can have multiple clauses.<br>
> Much like in the if-let with multiple clauses, I could imagine a for-loop with multiple<br>
> clauses:<br>
><br>
> var cards: [(Suit,Rank)] = []<br>
> for x in suits, y in ranks {<br>
> cards.append((x,y))<br>
> }<br>
><br>
> This would be the same as writing:<br>
><br>
> var cards: [(Suit,Rank)] = []<br>
> for x in suits {<br>
> for y in ranks {<br>
> cards.append((x,y))}<br>
> }<br>
> }<br>
><br>
> You could also do something like:<br>
><br>
> for x in input1, y in (x..> // Do something with (x,y)<br>
> }<br>
><br>
> In fact, once we would have that, we could combine both if-let and for, and make it more<br>
> general, to end up with something like Haskell’s do-notation or C#’s LINQ. But that might<br>
> be taking it too far...<br>
><br>
> Chris<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>
><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>
</blockquote></div>
</div></blockquote></div><br></div></div></div></div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=1p9Jer2O6jVE9KWvo-2B9iUaEyN8slp4IizyiLwsfp54NYpvY7n5DmMsk7FrmudA4OOjC3wyu14SNEohMGG-2FCOmbUofx3w-2BSMq7ATpOysNSSBlSs8PDhylbqyuOKv-2F4zFkVMcimXN-2Bxwb9PF8XdEr8-2B28xyVtmAxxEsiOYhlySI7k9K7rOd0gBtXZ92GMiIvrzThF8IZTtlS40C6ghOMx0fc5dS47Y-2F748eXF5BGbLNtg-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
</div>
<br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">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>
<br></blockquote></div><br></div>