Extension on List to directly map a list, without calling toList.
Always chaining map
and toList
when you want to map a List
is tiring, especially in a Flutter app development. Most of the time, we know we just want to map our list into another list, not into a lazy Iterable
.
This simple extension simplify the process.
Add package map_to_list
into project dependencies:
dart pub add map_to_list
And import the package into your project file:
import 'package:map_to_list/map_to_list.dart';
Then you could call a single mapToList
:
final list = [1, 2, 3, 4, 5];
final mapped = list.mapToList((value) => value * value);
Instead of always chaining map
and toList
:
final list = [1, 2, 3, 4, 5];
final squared = list.map((value) => value * value).toList();