[swift-evolution] [Idea] Remove optional pattern binding

Haravikk swift-evolution at haravikk.me
Mon May 2 09:52:51 CDT 2016


Ah, I’m just thinking about it in terms of too narrow a case, that makes sense! Put me down as a +1 for the change and solution then.

> On 2 May 2016, at 11:56, Антон Жилин <antonyzhilin at gmail.com> wrote:
> 
> Currently,
> 
> if case let x? = y { ... }
> 
> is a sugared version of:
> 
> if case let .some(x) = y { ... }
> 
> which is in turn a sugared version of:
> 
> if case .some(let x) = y { ... }
> 
> Pattern matching in `if` works like this: left hand side of `=` contains supposed structure of value at right hand side.
> If we omit `case`, we get:
> 
> if let x? = y { ... }
> 
> Another example: checks if tuple contains two `.some`:
> 
> if let (x?, y?) = z { ... }
> 
> - Anton
> 
> 2016-05-02 13:25 GMT+03:00 Haravikk <swift-evolution at haravikk.me <mailto:swift-evolution at haravikk.me>>:
> 
>> On 1 May 2016, at 09:12, Антон Жилин <antonyzhilin at gmail.com <mailto:antonyzhilin at gmail.com>> wrote:
>> 
>> Pattern binding for optionals will look like:
>> 
>> if let x? = y { … }
> 
> Would take a little getting used to, but I think I’d be fine with it, as the way things are now is inconsistent with regular assignments (which remain optional).
> 
> My only concern is why the question mark on the left hand side? I don’t really have any concrete reason against it, but it just feels kind of odd to me, I’m just hoping for some reasoning why some of the alternatives aren’t better fits like:
> 
> 	if let x = y? { … } // More like optional chaining, which is familiar as an “if non-nil proceed” behaviour
> 	if let x ?= y { … } // More obviously a special type of assignment that could fail if y is nil
> 
> Again, I’m in favour, I’m just curious why the mentioned format, were others considered previously, or is just because that’s how the case-keyword form does it? (I don’t use it as I’ve never liked that form, and it doesn’t seem that well known anyway).
> 

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


More information about the swift-evolution mailing list