[swift-evolution] Extending the for loop to have multiple clauses

Douglas Gregor dgregor at apple.com
Wed Dec 9 15:44:49 CST 2015


> On Dec 9, 2015, at 1:43 PM, Brent Royal-Gordon <brent at architechies.com> wrote:
> 
>>> I think it could be really nice to extend the for-loop so that it can have multiple clauses. Much like in the if-let with multiple clauses, I could imagine a for-loop with multiple clauses:
>>> 
>>> var cards: [(Suit,Rank)] = []
>>> for x in suits, y in ranks {
>>> cards.append((x,y))
>>> }
>> 
>> 
>> Isn’t this just
>> 
>> 	for (x, y) in zip2(suits, ranks) {
>> 	}
>> 
>> ?
> 
> No, apparently it’s supposed to be all permutations of both types. But I too read it as syntactic sugar for a zip, which I think is a great reason not to add this syntax.


Ah. In that case, I’d much rather have a library function that indicates that we’re getting all permutations. This doesn’t feel like it belongs in the language at all, but in the library.

	- Doug



More information about the swift-evolution mailing list