mapNotNull<E> method

Iterable<E> mapNotNull<E>(
  1. E? f(
    1. T? e
    )
)

Similar to map, but MAY return a non-nullable type.

int? f(String? e) => (e == null) ? 0 : e.length;

List<int?> list1 = ["xxx", "xx", null, "x"].map(f).toList();
expect(list1, isA<List<int?>>());

List<int?> list2 = ["xxx", "xx", null, "x"].mapNotNull(f).toList();
expect(list2, isA<List<int>>());

Implementation

Iterable<E> mapNotNull<E>(E? Function(T? e) f) => map(f).cast();