[swift-evolution] [DRAFT] Regularizing Where Grammar (was Re: Add a while clause to for loops)

Brent Royal-Gordon brent at architechies.com
Fri Jun 10 14:15:18 CDT 2016


> Following Brent's logic that the for-in where should mimic the switch statement functionality, then this example:
> 
> for (eachKey, eachValue) 
> where eachValue > 5 
> in theKeyValuePairs {... }
> 
> Should read like:
> 
> for (eachKey, eachValue where eachValue > 5) in theKeyValuePairs {... }
> 
> And,
> 
> for (eachKey, eachValue) 
> where eachKey % 2 == 0 && eachValue > 5
> in theKeyValuePairs {... }
> 
> Should read like:
> 
> for (eachKey where eachKey % 2 == 0, eachValue where eachValue > 5) 
> in theKeyValuePairs {... }

I'm not sure why you say that. This compiles:

	switch pair {
	case let (key, value) where key % 2 == 0 && value > 5:
		print("yes")
	default:
		print("no")
	}

While this fails to compile:

	switch pair {
	case let (key where key % 2, value where value > 5):
		print("yes")
	default:
		print("no")
	}

So where are your multiple, parenthesized `where` clauses coming from?

-- 
Brent Royal-Gordon
Architechies



More information about the swift-evolution mailing list