dart-lang / dart-lang/language
Requst: Optional parentheses for one argument arrow function
- Dominant language
- TeX
- Stars
- 2.9k
- Forks
- 239
- Avg merge
- 2d 18h
- Merged PRs (30d)
- 14
Description
Arrow functions, or lambdas as some languages call it, are frequently used in dart, even more so in the Flutter framework. Most of these arrow functions only contain one argument. At the language's current standing, if I were to write a `forEach` loop on a List, I would have to do something like this:
```dart
void main(List args) {
List list = [1,2,3,4];
list.forEach((item) => /* Do something item */);
}
```
`forEach` is just one of the many places that an arrow function is frequently used.
As you can see, the parentheses around the `item` make the whole arrow function a little awkward to write and also read. I propose the following change: make the parenthensis around one argument arrow functions optional, permitting writing code as such:
```dart
void main(List args) {
List list = [1,2,3,4];
list.forEach(item => /* Do something item */);
}
```
This makes the code much cleaner to read and to write.
Contributor guide
Assessment
This issue has not been assessed yet.