mapOrNull<TResult extends Object?> method
TResult?
mapOrNull<TResult extends Object?>({
- TResult? context(
- _ValueBuilderContext<
T> value
- _ValueBuilderContext<
- TResult? ref(
- _ValueBuilderRef<
T> value
- _ValueBuilderRef<
- TResult? value(
- _ValueBuilderValue<
T> value
- _ValueBuilderValue<
A variant of map that fallback to returning null.
It is equivalent to doing:
switch (sealedClass) {
case final Subclass value:
return ...;
case _:
return null;
}
Implementation
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>({TResult? Function( _ValueBuilderContext<T> value)? context,TResult? Function( _ValueBuilderRef<T> value)? ref,TResult? Function( _ValueBuilderValue<T> value)? value,}){
final _that = this;
switch (_that) {
case _ValueBuilderContext() when context != null:
return context(_that);case _ValueBuilderRef() when ref != null:
return ref(_that);case _ValueBuilderValue() when value != null:
return value(_that);case _:
return null;
}
}