Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: prefer_passing_constructor_as_a_function_to_map #58654

Closed
salahamassi opened this issue Feb 5, 2022 · 1 comment
Closed

proposal: prefer_passing_constructor_as_a_function_to_map #58654

salahamassi opened this issue Feb 5, 2022 · 1 comment
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. linter-lint-proposal linter-status-pending

Comments

@salahamassi
Copy link

prefer_passing_constructor_as_a_function_to_map

Description

Instead of providing a closure to the Iterable map method, we can provide directly an appropriate constructor as a function to map method.

Details

When we use a map function to map the list of items from one type to another type, we can do this simply by providing a simple closure to the map method with transformation code, now after dart Allow passing constructors as functions, we can remove the boilerplate transformation code and pass the constructor directly to map method.

Kind

Style

Good Examples

final List<User> usersObjects = users.map(User.fromMap).toList();

Bad Examples

final List<User> usersObjects = users.map((e) => User.fromMap(e)).toList();

@bwilkerson
Copy link
Member

I believe that unnecessary_lambdas ought to cover this case. If it doesn't I'd consider that a bug.

@devoncarew devoncarew added analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Nov 19, 2024
@devoncarew devoncarew transferred this issue from dart-lang/linter Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. linter-lint-proposal linter-status-pending
Projects
None yet
Development

No branches or pull requests

3 participants