# prefer-map-keys-values

Prefer Map.keys or Map.values when one entry component is unused

Iterating `Map.entries` constructs key-value pairs even when one component is never used.
Instead, you SHOULD iterate `Map.keys` or `Map.values` directly.

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

## Reported

```ds title="main.ds"
function copy(values: Map<string, int32>, output: int32[]): void {
    for (const (_, value) of values.entries()) {
        output.push(value);
    }
}
```

## Accepted

```ds title="main.ds"
function copy(values: Map<string, int32>, output: int32[]): void {
    for (const value of values.values()) {
        output.push(value);
    }
}
```

## Prior art

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

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