[swift-evolution] [Pitch] Guarding on enum values

Félix Cloutier felixcca at yahoo.ca
Wed Dec 23 08:59:51 CST 2015


I feel exactly like Brent.

Félix

> Le 23 déc. 2015 à 04:15:24, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> a écrit :
> 
>>   guard case let .Succeed(m) = returnsResult() else {
>>        return it
>>   }
>>   // Can safely use m, otherwise Result is passed back the call stack.
> 
> I didn't understand what you wanted to begin with, so to summarize: you want to be able to bind the return value of `returnsResult()` to a constant on the `else` branch if the pattern doesn't match.
> 
> I definitely see the use case here, but I can't say I like the implicit use of `it`. If we did something like this, I would prefer it be done by decorating the `else`:
> 
> 	guard case let .Succeed(m) = returnsResult() else let r {
> 		return r
> 	}
> 
> However, I'm honestly not sure that's much less burdensome than this:
> 
> 	let r = returnsResult()
> 	guard case let .Succeed(m) = r else {
> 		return r
> 	}
> 
> It *is* a line less, and a constant less, but it also means adding a new and slightly funky syntax to the language. I'm just not sure it's worth it.
> 
> -- 
> Brent Royal-Gordon
> Architechies
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution



More information about the swift-evolution mailing list