# prefer-map-over-and-then

Prefer Result map methods when chaining only rewraps one variant

A Result chain that always rebuilds the same variant cannot introduce the opposite outcome.
Instead, you SHOULD use `map` or `mapErr` and return the transformed payload directly.

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

## Reported

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

## Accepted

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

## Prior art

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

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