Let's fix `if let` syntax

Isn't this more of

  • Shorthand syntactic sugar for 'variable shadowing'

rather than if let, guard let or case let etc?

Because I mean, type casting if let v = v as? OtherType { ... } is not included in this discussion, is it?
Also as mentioned by @ensan-hcl , if a value is chained, it would not work.


Keyword unwrap sounds natural to me as it is already used in stdlib:

Something like this?
If new syntax must be used with existing if keywords:

let optionalValue: Int?

if unwrapped optionalValue { ... } // <- Past tense sounds more natural, I guess
// or
if unwrap optionalValue { ... }

guard unwrapped optionalValue else { ... }
// or
guard unwrap optionalValue { ... }

However, it would be also nice if it can be used standalone:

let optionalValue: Int?

unwrap optionalValue { ... } // In this context present tense sounds natural
unwrap optionalValue else { ... } // awkward?

Similar thread:

3 Likes