mapOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
  1. TResult? mentionRule(
    1. UDraftThreadgateAllowMentionRule value
    )?,
  2. TResult? followerRule(
    1. UDraftThreadgateAllowFollowerRule value
    )?,
  3. TResult? followingRule(
    1. UDraftThreadgateAllowFollowingRule value
    )?,
  4. TResult? listRule(
    1. UDraftThreadgateAllowListRule value
    )?,
  5. TResult? unknown(
    1. UDraftThreadgateAllowUnknown 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( UDraftThreadgateAllowMentionRule value)?  mentionRule,TResult? Function( UDraftThreadgateAllowFollowerRule value)?  followerRule,TResult? Function( UDraftThreadgateAllowFollowingRule value)?  followingRule,TResult? Function( UDraftThreadgateAllowListRule value)?  listRule,TResult? Function( UDraftThreadgateAllowUnknown value)?  unknown,}){
final _that = this;
switch (_that) {
case UDraftThreadgateAllowMentionRule() when mentionRule != null:
return mentionRule(_that);case UDraftThreadgateAllowFollowerRule() when followerRule != null:
return followerRule(_that);case UDraftThreadgateAllowFollowingRule() when followingRule != null:
return followingRule(_that);case UDraftThreadgateAllowListRule() when listRule != null:
return listRule(_that);case UDraftThreadgateAllowUnknown() when unknown != null:
return unknown(_that);case _:
  return null;

}
}