Skip to content
This repository has been archived by the owner on Jun 13, 2020. It is now read-only.

If destructuring #698

Open
kiljacken opened this issue Feb 13, 2016 · 5 comments
Open

If destructuring #698

kiljacken opened this issue Feb 13, 2016 · 5 comments

Comments

@kiljacken
Copy link
Member

Liam suggested also allowing the use of if when destructuring a union enum. It would look something like the following:

x := thisReturnsAnOption();
if Some(val) := x {
    // Do stuff with val
}

I'm not sure if I find this neccesary as we have match statement, but what does everybody think?

If we were to implement this the by far easiest way is to transform it into the equivalent match structure, as to not special case things further. That would mean that we turn the previous if into:

match x {
    Some(val) => {
        // Do stuff with val
    }
    _ => {},
}
@MovingtoMars
Copy link
Member

How would that work with else if

@kiljacken
Copy link
Member Author

Ugh, didn't think about that.

@kiljacken
Copy link
Member Author

I guess it wouldn't be too bad special casing wise, so no biggie

@felixangell
Copy link
Member

Looks good to me 👍

@MovingtoMars
Copy link
Member

Rust and Swift both do this, I believe.

@felixangell felixangell added this to the bootstrap milestone Mar 2, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants