[swift-evolution] Allow let binding of non-optionals

Guillaume Lessard glessard at tffenterprises.com
Fri Jan 8 12:53:07 CST 2016


> On 7 janv. 2016, at 12:02, Joe Groff via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 'case let' already works like this, by declaring a pattern 'let a' that unconditionally matches anything.

This is an interesting workaround! However, outside of switch statements I don’t think I’ve used a “case let” that made for clear re-reading. Maybe I’m hobbled by switches.

The workaround I’ve used for Russ’s situation is to build a temporary Optional; `case let` hardly helps:

if let x = x, y = Optional(calculate(x, z)) where condition(x, y) { print(x, y) }

if let x = x, case let y = calculate(x, z) where condition(x, y) { print(x, y) }

In any case, I agree with Russ that this variable binding behaviour is an occasional irritant.

Guillaume Lessard



More information about the swift-evolution mailing list