# prefer-maybe

Prefer the maybe operator over manual propagation

Explicit branching that immediately propagates a Result error or nullish value repeats the behavior of the maybe operator.
Instead, you SHOULD use the maybe operator to propagate absence or failure.

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

## Reported

```ds title="main.ds"
function value(result: Result<int32, string>): Result<int32, string> {
    const value = match (result) {
        Ok { value } => value
        Err { error } => return Result.err(error)
    };
    return Result.ok(value);
}
```

## Accepted

```ds title="main.ds"
function value(result: Result<int32, string>): Result<int32, string> {
    const value = result?;
    return Result.ok(value);
}
```

## Prior art

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

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