mapToNullableList<R> method

List<R>? mapToNullableList<R>(
  1. R mapperFunction(
    1. E item
    )
)

Maps this iterable to a nullable List using mapperFunction.

Returns null if this iterable is null or empty.

Example:

List<int>? numbers = null;
List<String>? strings = numbers.mapToNullableList((n) => n.toString()); // null

Implementation

List<R>? mapToNullableList<R>(R Function(E item) mapperFunction) {
  return isNullOrEmpty ? null : this!.map((e) => mapperFunction(e)).toList();
}