Swift: "if let" and "while let" might as well support full pattern matching the way "switch...case" does
| Originator: | pyry.jahkola | ||
| Number: | rdar://20185737 | Date Originated: | 2015-03-17 |
| Status: | Duplicate of 19382905 (Open/Closed) | Resolved: | |
| Product: | Developer Tools | Product Version: | |
| Classification: | Feature (new) | Reproducible: |
Summary:
It seems to me the switch statement gets a bit heavy when I only need to pattern match one specific case and make a side effect with the associated values of the matched enum. Why not support this syntax in "if let" and "while let" too?
```
enum EitherString {
case Value(String)
case Error(String)
}
let x: EitherString = ...
if let .Value(value) = x {
println(value)
}
```
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!
This is also how Rust does "if let", and would be useful indeed: https://github.com/rust-lang/rfcs/pull/160