# prefer-eager-fallback

Prefer eager fallbacks when deferred evaluation cannot avoid work

`Result.unwrapOrElse` adds an unnecessary callback when its fallback is `Copy` and effect-free.
Instead, you SHOULD pass the expression directly to `unwrapOr`.

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

## Reported

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

## Accepted

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

## Prior art

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

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