# redundant-pattern-matching

Prefer canonical result predicates over boolean pattern matches

A match that maps `Ok` and `Err` directly to opposite boolean values only tests the result variant.
Instead, you SHOULD call `isOk()` or `isErr()` on the result.

- Category: suspicious
- Level: warning
- Fix: suggestion
- Scope: module

## Reported

```ds title="main.ds"
function succeeded(result: Result<int32, string>): boolean {
    return match (result) {
        Ok { value: _ } => true
        Err { error: _ } => false
    };
}
```

## Accepted

```ds title="main.ds"
function succeeded(result: Result<int32, string>): boolean {
    return result.isOk();
}
```

## Prior art

- [Clippy · redundant_pattern_matching](https://rust-lang.github.io/rust-clippy/master/index.html#redundant_pattern_matching)

[language/linter/src/rules/suspicious/redundant_pattern_matching.rs:8](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/suspicious/redundant_pattern_matching.rs#L8)
