mapNonNull<E> method

Iterable<E>? mapNonNull<E>(
  1. E? f(
    1. T element
    )
)

Maps over the iterable and skips null values, returning null if the iterable itself is null

Implementation

Iterable<E>? mapNonNull<E>(E? Function(T element) f) {
  // If the iterable is null, return null
  if (this == null) return <E>[];
  // Otherwise, apply the map function
  return (this ?? <T?>[])
      .where((e) => e != null)
      .map((e) => f(e as T))
      .where((e) => e != null)
      .cast<E>();

  /// Cast to non-nullable type
}