mapToListWhere<R> method

List<R> mapToListWhere<R>(
  1. R toElement(
    1. T e
    ),
  2. bool test(
    1. T e
    ), {
  3. bool growable = false,
})

Creates a List with all elements of this Iterable that satisfy the predicate test and modified by toElement.

The List is fixed-length if growable is false.

Implementation

List<R> mapToListWhere<R>(
  R Function(T e) toElement,
  bool Function(T e) test, {
  bool growable = false,
}) {
  final list = <R>[];
  for (final element in this) {
    if (test(element)) list.add(toElement(element));
  }
  return growable ? list : list.toFixedList();
}