# prefer-tuple-swap

Prefer tuple assignment for swaps

Swapping two places through a temporary spreads one parallel assignment across three statements.
Instead, you SHOULD assign the reversed tuple directly to both places.

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

## Reported

```ds title="main.ds"
function swap(left: int32, right: int32): (int32, int32) {
    let first = left;
    let second = right;
    const temporary = first;
    first = second;
    second = temporary;

    return (first, second);
}
```

## Accepted

```ds title="main.ds"
function swap(left: int32, right: int32): (int32, int32) {
    let first = left;
    let second = right;
    (first, second) = (second, first);

    return (first, second);
}
```

## Prior art

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

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