# prefer-match

Prefer match over switch statements and repeated equality chains

Repeated equality branches and switch cases encode selection as independent statements.
Instead, you SHOULD use `match` to bind the selected value and its cases in one expression.

- Category: style
- Level: warning
- Fix: none
- Scope: module

## Reported

```ds title="main.ds"
function describe(value: int32): string {
    if (value === 0) {
        return "zero";
    } else if (value === 1) {
        return "one";
    } else if (value === 2) {
        return "two";
    }

    return "many";
}
```

## Accepted

```ds title="main.ds"
function describe(value: int32): string {
    return match (value) {
        0 => "zero"
        1 => "one"
        2 => "two"
        _ => "many"
    };
}
```

[language/linter/src/rules/style/prefer_match.rs:7](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/style/prefer_match.rs#L7)
