News for hackers. Stuff that matters.
Re:Server APIs Project by ahmedk92 on Tuesday October 25, 2016 @03:30PM (#12790928)
Also a significant drop in null dereferencing issues. The `if-let` syntax is brilliant.
Re:Server APIs Project by tomjakubowski on Tuesday October 25, 2016 @04:55PM (#12791579)
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<>).
Re:Server APIs Project by steveklabnik on Tuesday October 25, 2016 @09:49PM (#12793293)
Worth noting that we got the idea for if let from Swift :)
Re:Server APIs Project by trevor-e on Wednesday October 26, 2016 @12:23AM (#12793864)
These are the little things I love seeing on HN. :)
Re:Server APIs Project by austinz on Tuesday October 25, 2016 @05:07PM (#12791651)
Swift has "if case let" for that use case. (Admittedly, the syntax is a bit esoteric.)
Re:Server APIs Project by ahmedk92 on Wednesday October 26, 2016 @01:55PM (#12798800)
You can use `as?`:

if let string = thing as? String