# prefer-flat

Prefer Array.flat over spreading nested arrays into concat

Spreading nested arrays into `concat` manually performs one-level flattening.
Instead, you SHOULD call `flat` on the nested array.

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

## Reported

```ds title="main.ds"
function flatten(values: int32[][]): int32[] {
    return Array<int32>.new().concat(...values);
}
```

## Accepted

```ds title="main.ds"
function flatten(values: int32[][]): int32[] {
    return values.flat();
}
```

## Prior art

- [eslint-plugin-unicorn · prefer-array-flat](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-array-flat.md)

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