mapOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
  1. TResult? system(
    1. ParsedInstructionSystem value
    )?,
  2. TResult? splToken(
    1. ParsedInstructionSplToken value
    )?,
  3. TResult? memo(
    1. ParsedInstructionMemo value
    )?,
  4. TResult? unsupported(
    1. ParsedInstructionUnsupported value
    )?,
})

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( ParsedInstructionSystem value)?  system,TResult? Function( ParsedInstructionSplToken value)?  splToken,TResult? Function( ParsedInstructionMemo value)?  memo,TResult? Function( ParsedInstructionUnsupported value)?  unsupported,}){
final _that = this;
switch (_that) {
case ParsedInstructionSystem() when system != null:
return system(_that);case ParsedInstructionSplToken() when splToken != null:
return splToken(_that);case ParsedInstructionMemo() when memo != null:
return memo(_that);case ParsedInstructionUnsupported() when unsupported != null:
return unsupported(_that);case _:
  return null;

}
}