# redundant-closure

Disallow closures that only forward their arguments to another function

A closure that passes each parameter unchanged to one function adds another callable value and invocation without changing the call.
Instead, you SHOULD pass the function directly when the forwarded arguments require no adjustments.

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

## Reported

```ds title="main.ds"
declare function square(value: int32): int32;

function squares(values: int32[]): Iterator<int32> {
    return values.iterator().map((value) => square(value));
}
```

## Accepted

```ds title="main.ds"
declare function square(value: int32): int32;

function squares(values: int32[]): Iterator<int32> {
    return values.iterator().map(square);
}
```

## Prior art

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

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