mapNotNullTo<R> method

List<R> mapNotNullTo<R>(
  1. List<R> destination,
  2. R? transform(
    1. T
    )
)

Applies the given transform function to each element in the original collection and appends only the non-null results to the given destination.

Implementation

List<R> mapNotNullTo<R>(List<R> destination, R? Function(T) transform) {
  for (final item in this) {
    final result = transform(item);
    if (result != null) {
      destination.add(result);
    }
  }
  return destination;
}