News for hackers. Stuff that matters.
Re:Swift 1.2 and Xcode 6.3 beta by masklinn on Monday February 09, 2015 @04:01PM (#9023693)
I'd like to see them expand it the way Rust did: Rust lifted `if let` from Swift (I believe) but made it a more general-purpose refutable pattern matcher, it's just one step below match and works with any enum type not just Option. So you can write:

    enum Foo {
        Bar,
        Baz(i32),
        Qux(f64)
    }

    if let Bar = item {
        // do something
    } else if let Baz(val) = other {
        // do something with val
    }
which is oft shorter than a full-blown `match`, and more convenient when alternating on different "source" items.
Re:Swift 1.2 and Xcode 6.3 beta by oleganza on Monday February 09, 2015 @04:34PM (#9023897)
Swift borrowed "if let" from Rust, not the other way around.
Re:Swift 1.2 and Xcode 6.3 beta by CUViper on Monday February 09, 2015 @04:47PM (#9023968)
"The if let construct is based on the precedent set by Swift,"

https://github.com/rust-lang/rfcs/blob/master/text/0160-if-l...

Re:Swift 1.2 and Xcode 6.3 beta by eridius on Monday February 09, 2015 @05:36PM (#9024248)
That's putting it a bit mildly. Speaking as the author of that RFC, Rust's "if let" would never have existed if it were not for Swift. When I saw Swift's "if let" I immediately knew I wanted it in Rust. I also generalized it to arbitrary patterns at that time, since Rust doesn't fetishize Option the way Swift fetishizes Optional.

I am glad to see Swift 1.2 expanding "if let" to multiple clauses. But I do wish it supported arbitrary values instead of just Optional.

Re:Swift 1.2 and Xcode 6.3 beta by oleganza on Monday February 09, 2015 @04:57PM (#9024038)
Wow. Such a rapid feedback loop here. Thanks for sharing.