<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">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" class="">http://norvig.com/spell-correct.html</a>) would then be very straightforward to port.<div class=""><br class=""></div><div class="">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 class=""><div class=""><br class=""></div><div class="">Chris<br class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On 09 Dec 2015, at 15:48, Jacob Bandes-Storch &lt;<a href="mailto:jtbandes@gmail.com" class="">jtbandes@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class="">Are you expecting that this could be combined with "where" clauses?<br class=""><br class="">for x in range1 where x%2==0, y in range2 where y%3==0 {}<br class=""><br class="">for x in range1, y in range2 where x%2==0 &amp;&amp; y%3==0 {}<br class=""><br class="">I think it's a good idea, but the implications may be less than obvious.<br class=""><div class="gmail_quote"><div dir="ltr" class="">On Wed, Dec 9, 2015 at 12:37 PM <a href="mailto:krzysztof@siejkowski.net" class="">krzysztof@siejkowski.net</a> via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""></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 class="">
<br class="">
<br class="">
-----Original Message-----<br class="">
From:&nbsp;Chris Eidhof via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;<br class="">
Reply:&nbsp;Chris Eidhof &lt;<a href="mailto:chris@eidhof.nl" target="_blank" class="">chris@eidhof.nl</a>&gt;<br class="">
Date:&nbsp;December 9, 2015 at 9:00:26 PM<br class="">
To:&nbsp;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a> &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;<br class="">
Subject:&nbsp; [swift-evolution] Extending the for loop to have multiple clauses<br class="">
<br class="">
&gt; I think it could be really nice to extend the for-loop so that it can have multiple clauses.<br class="">
&gt; Much like in the if-let with multiple clauses, I could imagine a for-loop with multiple<br class="">
&gt; clauses:<br class="">
&gt;<br class="">
&gt; var cards: [(Suit,Rank)] = []<br class="">
&gt; for x in suits, y in ranks {<br class="">
&gt; cards.append((x,y))<br class="">
&gt; }<br class="">
&gt;<br class="">
&gt; This would be the same as writing:<br class="">
&gt;<br class="">
&gt; var cards: [(Suit,Rank)] = []<br class="">
&gt; for x in suits {<br class="">
&gt; for y in ranks {<br class="">
&gt; cards.append((x,y))}<br class="">
&gt; }<br class="">
&gt; }<br class="">
&gt;<br class="">
&gt; You could also do something like:<br class="">
&gt;<br class="">
&gt; for x in input1, y in (x..&gt; // Do something with (x,y)<br class="">
&gt; }<br class="">
&gt;<br class="">
&gt; In fact, once we would have that, we could combine both if-let and for, and make it more<br class="">
&gt; general, to end up with something like Haskell’s do-notation or C#’s LINQ. But that might<br class="">
&gt; be taking it too far...<br class="">
&gt;<br class="">
&gt; Chris<br class="">
&gt; _______________________________________________<br class="">
&gt; swift-evolution mailing list<br class="">
&gt; <a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class="">
&gt; <a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
&gt;<br class="">
<br class="">
_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class="">
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class="">
</blockquote></div>
</div></blockquote></div><br class=""></div></div></div></body></html>