maybeMap<TResult extends Object?> method

  1. @optionalTypeArgs
TResult maybeMap<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
    )?,
  6. required TResult orElse(),
})

A variant of map that fallback to returning orElse.

It is equivalent to doing:

switch (sealedClass) {
  case final Subclass value:
    return ...;
  case _:
    return orElse();
}

Implementation

@optionalTypeArgs TResult maybeMap<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,required TResult orElse(),}){
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 orElse();

}
}