mapNonNull<R> method
R?
mapNonNull<R>(
- R fn(
- T
Transforms a non-null value with fn, or returns null when the receiver
is null.
The null-propagating cousin of a plain map: avoids calling fn on null
while still letting the result type R differ from T.
Example:
const int? n = 3;
n.mapNonNull((v) => v * 2); // 6
null.mapNonNull((v) => v); // null
Implementation
R? mapNonNull<R>(R Function(T) fn) {
final T? self = this;
return self == null ? null : fn(self);
}