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

Haravikk swift-evolution at haravikk.me
Mon May 2 05:25:16 CDT 2016

> On 1 May 2016, at 09:12, Антон Жилин <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/50d2cc56/attachment.html>

More information about the swift-evolution mailing list