# prefer-lazy-fallback

Prefer lazy fallbacks when eager arguments perform avoidable work

An eager `Result` fallback is evaluated even when the result already contains a value.
Instead, you SHOULD pass a callback to `unwrapOrElse` when evaluating the fallback can trap or perform work.

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

## Reported

```ds title="main.ds"
declare function recover(): int32;

function value(result: Result<int32, string>): int32 {
    return result.unwrapOr(recover());
}
```

## Accepted

```ds title="main.ds"
declare function recover(): int32;

function value(result: Result<int32, string>): int32 {
    return result.unwrapOrElse(() => recover());
}
```

## Prior art

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

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