Skip to content

Syntax proposal if let #1301

@jaredly

Description

@jaredly

In swift, there's this nice construct for simple destructuring

if case .someEnumVariant(let value) {
 ...
} else {
 ...
}

It's basically a one-armed match.
It would be super handy to have that for reason, and I imagine it would look like

if let [%pattern] = [%value] {
  // x
} else {
  // y
}

which we'd translate to

switch [%value] {
| [%pattern] => // x
| _ => // y
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Parserparsing reason code into an ASTRFCFor larger proposals/ideas that will need discussion

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions