mapNonNull<R> method

List<R> mapNonNull<R>(
  1. R f(
    1. T element
    )
)

Maps over the list and skips null values, returning an empty list if the list itself is null

Implementation

List<R> mapNonNull<R>(R Function(T element) f) {
  // If the list is null, return an empty list
  if (this == null) return <R>[];

  // Filter out null values and apply the map function
  return this
          ?.where((e) => e != null) // Filter out null values from the list
          .map(
              (e) => f(e as T)) // Apply the map function to non-null elements
          .toList() ??
      <R>[]; // Return the result as a list
}