Re:Swift 1.2 and Xcode 6.3 beta
by WildUtah on Monday February 09, 2015 @05:34PM
(#9024233)
if-let is great. I don't know where it started (apparently upthread they say Rust and swift have been swapping the idea) but Clojure has had it since 2008.[0]
[0] https://clojuredocs.org/clojure.core/if-let
[ Parent
| on HN ]
C++98 (maybe earlier) has a similar feature:
if (mytype* p = find_or_null(blah))
foo(*p);
Still have to dereference p, but at least it's only in scope when doing so is safe. Also goes well with auto and std::optional: if (auto opt = find_or_none(blah))
foo(*opt);I imagine everything in Swift has been borrowed from another language. OCaml, Go, etc. I'd be more interested in other great language features that are missing from Swift that are in other "classic" languages like OCaml, for instance.