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

Антон Жилин antonyzhilin at gmail.com
Sun May 1 03:12:34 CDT 2016


Generally, pattern binding in `if` looks like this:

if case *pattern* = *expression* { ... }

Pattern binding for optionals is currently usable as both of:

if case let .some(x) = y { ... }
if case let x? = y { ... }

Now, there is also an older optional-specific hack:

if let x = y { ... }

In terms of pattern binding, it should always be true, and it's illogical
inside `if`.

I suggest:
1) Remove optional pattern binding
2) Remove `case` in `if` pattern binding

Really, `case` should be an attribute of `switch`, not `if`.

Pattern binding for optionals will look like:

if let x? = y { ... }

It will become more explicit and consistent with the rest of the language.

We need to hurry until Swift 3 lands!

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


More information about the swift-evolution mailing list