<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 <<a href="mailto:jtbandes@gmail.com" class="">jtbandes@gmail.com</a>> 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 && 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 <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> 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: Chris Eidhof via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>><br class="">
Reply: Chris Eidhof <<a href="mailto:chris@eidhof.nl" target="_blank" class="">chris@eidhof.nl</a>><br class="">
Date: December 9, 2015 at 9:00:26 PM<br class="">
To: <a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a> <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>><br class="">
Subject: [swift-evolution] Extending the for loop to have multiple clauses<br class="">
<br class="">
> I think it could be really nice to extend the for-loop so that it can have multiple clauses.<br class="">
> Much like in the if-let with multiple clauses, I could imagine a for-loop with multiple<br class="">
> clauses:<br class="">
><br class="">
> var cards: [(Suit,Rank)] = []<br class="">
> for x in suits, y in ranks {<br class="">
> cards.append((x,y))<br class="">
> }<br class="">
><br class="">
> This would be the same as writing:<br class="">
><br class="">
> var cards: [(Suit,Rank)] = []<br class="">
> for x in suits {<br class="">
> for y in ranks {<br class="">
> cards.append((x,y))}<br class="">
> }<br class="">
> }<br class="">
><br class="">
> You could also do something like:<br class="">
><br class="">
> for x in input1, y in (x..> // Do something with (x,y)<br class="">
> }<br class="">
><br class="">
> In fact, once we would have that, we could combine both if-let and for, and make it more<br class="">
> general, to end up with something like Haskell’s do-notation or C#’s LINQ. But that might<br class="">
> be taking it too far...<br class="">
><br class="">
> Chris<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="">
><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>