[swift-evolution] [Draft] Tuple-Based Compound Optional Binding

Brent Royal-Gordon brent at architechies.com
Sun Jun 12 12:28:39 CDT 2016


>> 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 { ... }

It seems fair to mention that, so I've added it to the "Alternatives Considered" entry for doing nothing.
Not accepting this proposal

This proposal does not add new functionality; it merely removes keyword clutter. However, it offers a convenient replacement for a commonly-used feature which has just been removed as a result of grammatical ambiguity, not user confusion or lack of utility.

The same functionality is also available through case conditions:

guard case let (a?, b?, c?) = (opt1, opt2, opt3) else { ... }
However, all of optional binding is redundant with case conditions; we keep it anyway because it's a convenient shorthand and saves beginners from having to learn about pattern matching. Multiple bindings are a natural fit for the subset of case features available through optional binding.



-- 
Brent Royal-Gordon
Architechies

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160612/4f2bb833/attachment.html>


More information about the swift-evolution mailing list