mapNotNull<R extends Object> method

Stream<R> mapNotNull<R extends Object>(
  1. R? transform(
    1. T
    )
)

Returns a Stream containing only the non-null results of applying the given transform function to each element of this Stream.

Example

Stream.fromIterable(['1', 'two', '3', 'four'])
  .mapNotNull(int.tryParse)
  .listen(print); // prints 1, 3

// equivalent to:

Stream.fromIterable(['1', 'two', '3', 'four'])
  .map(int.tryParse)
  .whereType<int>()
  .listen(print); // prints 1, 3

Implementation

Stream<R> mapNotNull<R extends Object>(R? Function(T) transform) =>
    MapNotNullStreamTransformer<T, R>(transform).bind(this);