3 ms·
Also a significant drop in null dereferencing issues. The `if-let` syntax is brilliant.
by ahmedk92 10y ago
Also a significant drop in null dereferencing issues. The `if-let` syntax is brilliant.
- tomjakubowski 10y agoNot as general or useful as Rust's "if let", though. Rust's "if let" affords fallible pattern matching on arbitrary types, not just on "nullable pointer types" (in Safe Rust, a "nullable pointer" is simply a regular reference wrapped in Option<>).
- austinz 10y agoSwift has "if case let" for that use case. (Admittedly, the syntax is a bit esoteric.)
- steveklabnik 10y agoWorth noting that we got the idea for if let from Swift :)
- trevor-e 10y agoThese are the little things I love seeing on HN. :)
- ahmedk92 10y agoYou can use `as?`: if let string = thing as? String