[swift-evolution] [Draft] Tuple-Based Compound Optional Binding
Patrick Smith
pgwsmith at gmail.com
Mon Jun 13 22:32:18 CDT 2016
If Pyry’s suggestion remained the preferred way of unwrapping a tuple, could it also become the only way for unwrapping a single item?
guard case let a? = opt1 {...}
Or even shortened for matching optionals only:
guard let a? = opt1 {...}
Or even as has often been requested, to keep the same name:
guard let opt1? {...}
Multiples:
guard let (opt1?, opt2?, opt3?) {...}
guard let (a?, b?, c?) = (opt1, opt2, opt3) {...}
Sorry, not trying to derail, but it always has seemed like something shorter and more self explanatory could be made for optionals. `?` in pattern matching is a special syntax anyway, so why not make this common use case easier?
Patrick
_____________________________
From: Pyry Jahkola via swift-evolution <swift-evolution at swift.org>
Sent: Sunday, June 12, 2016 10:04 PM
Subject: Re: [swift-evolution] [Draft] Tuple-Based Compound Optional Binding
To: Brent Royal-Gordon <brent at architechies.com>
Cc: swift-evolution List <swift-evolution at swift.org>
On 12 Jun 2016, at 14:46, Brent Royal-Gordon via swift-evolution <swift-evolution at swift.org> wrote:
guard let (a, b, c) = (opt1, opt2, opt3) else { ... }
You mention `guard case` in the motivation, but I think for the uninitiated reader it would be fair to point out that the following example already works equivalently, with only a few extra characters:
guard case let (a?, b?, c?) = (opt1, opt2, opt3) else { ... }
Aside of that, it's yet more magic to our `if let` syntax but I don't mind, it would be useful at times.
— Pyry
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160614/7023ac1f/attachment.html>
More information about the swift-evolution
mailing list