# prefer-nth

Prefer nth over drop followed by first

Calling `first` after `drop` builds an adapter solely to consume its first value.
Instead, you SHOULD use `nth` to skip preceding values and return the selected value.

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

## Reported

```ds title="main.ds"
import { Iterator } from "destack:iter";

function select(values: Iterator<int32>, index: isize): int32 | undefined {
    return values.drop(index).first();
}
```

## Accepted

```ds title="main.ds"
import { Iterator } from "destack:iter";

function select(values: Iterator<int32>, index: isize): int32 | undefined {
    return values.nth(index);
}
```

## Prior art

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

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