Y
Hacker News
new
|
ask
|
show
|
jobs
by
ahmedk92
3523 days ago
Also a significant drop in null dereferencing issues. The `if-let` syntax is brilliant.
1 comments
tomjakubowski
3523 days ago
Not 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<>).
link
steveklabnik
3523 days ago
Worth noting that we got the idea for if let from Swift :)
link
trevor-e
3523 days ago
These are the little things I love seeing on HN. :)
link
austinz
3523 days ago
Swift has "if case let" for that use case. (Admittedly, the syntax is a bit esoteric.)
link
ahmedk92
3522 days ago
You can use `as?`:
if let string = thing as? String
link