mapOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
  1. TResult? repoRef(
    1. UModEventViewSubjectRepoRef value
    )?,
  2. TResult? repoStrongRef(
    1. UModEventViewSubjectRepoStrongRef value
    )?,
  3. TResult? messageRef(
    1. UModEventViewSubjectMessageRef value
    )?,
  4. TResult? convoRef(
    1. UModEventViewSubjectConvoRef value
    )?,
  5. TResult? unknown(
    1. UModEventViewSubjectUnknown 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( UModEventViewSubjectRepoRef value)?  repoRef,TResult? Function( UModEventViewSubjectRepoStrongRef value)?  repoStrongRef,TResult? Function( UModEventViewSubjectMessageRef value)?  messageRef,TResult? Function( UModEventViewSubjectConvoRef value)?  convoRef,TResult? Function( UModEventViewSubjectUnknown value)?  unknown,}){
final _that = this;
switch (_that) {
case UModEventViewSubjectRepoRef() when repoRef != null:
return repoRef(_that);case UModEventViewSubjectRepoStrongRef() when repoStrongRef != null:
return repoStrongRef(_that);case UModEventViewSubjectMessageRef() when messageRef != null:
return messageRef(_that);case UModEventViewSubjectConvoRef() when convoRef != null:
return convoRef(_that);case UModEventViewSubjectUnknown() when unknown != null:
return unknown(_that);case _:
  return null;

}
}