proposal: prefer_passing_constructor_as_a_function_to_map
#58654
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
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();
The text was updated successfully, but these errors were encountered: