flatMap<E> method

E? flatMap<E>(
  1. E? f(
    1. T object
    )
)

Transforms the object using the provided function if it is not null, otherwise returns null.

Example usage:

void main() {
  const String name = 'John';

  final String? capitalized = name.flatMap((value) => value.toUpperCase());

  print(capitalized); // Output: JOHN
}

Implementation

E? flatMap<E>(E? Function(T object) f) => this != null ? f(this as T) : null;