# prefer-clear

Prefer clear over discarding a complete drain

Discarding a complete drain constructs an Iterator whose removed values are never observed.
Instead, you SHOULD call `clear` to remove the values directly.

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

## Reported

```ds title="main.ds"
function reset(values: int32[]): void {
    values.drain();
}
```

## Accepted

```ds title="main.ds"
function reset(values: int32[]): void {
    values.clear();
}
```

## Prior art

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

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