# unused-peekable

Disallow peekable iterators that are never peeked

Wrapping an iterator with `peekable` adds buffered state when no use observes the next value.
Instead, you SHOULD use the original iterator until lookahead is required.

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

## Reported

```ds title="main.ds"
function consume(values: int32[]): void {
    const iterator = values.iterator().peekable();
    iterator.next();
}
```

## Accepted

```ds title="main.ds"
function consume(values: int32[]): void {
    const iterator = values.iterator();
    iterator.next();
}
```

## Prior art

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

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