mapOrNull<TResult extends Object?> method

  1. @optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
  1. TResult? profileViewDetailed(
    1. UNotificationGetGroupedNotificationsRelatedViewsProfileViewDetailed value
    )?,
  2. TResult? blockedPost(
    1. UNotificationGetGroupedNotificationsRelatedViewsBlockedPost value
    )?,
  3. TResult? generatorView(
    1. UNotificationGetGroupedNotificationsRelatedViewsGeneratorView value
    )?,
  4. TResult? notFoundPost(
    1. UNotificationGetGroupedNotificationsRelatedViewsNotFoundPost value
    )?,
  5. TResult? postView(
    1. UNotificationGetGroupedNotificationsRelatedViewsPostView value
    )?,
  6. TResult? starterPackView(
    1. UNotificationGetGroupedNotificationsRelatedViewsStarterPackView value
    )?,
  7. TResult? unknown(
    1. UNotificationGetGroupedNotificationsRelatedViewsUnknown 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( UNotificationGetGroupedNotificationsRelatedViewsProfileViewDetailed value)?  profileViewDetailed,TResult? Function( UNotificationGetGroupedNotificationsRelatedViewsBlockedPost value)?  blockedPost,TResult? Function( UNotificationGetGroupedNotificationsRelatedViewsGeneratorView value)?  generatorView,TResult? Function( UNotificationGetGroupedNotificationsRelatedViewsNotFoundPost value)?  notFoundPost,TResult? Function( UNotificationGetGroupedNotificationsRelatedViewsPostView value)?  postView,TResult? Function( UNotificationGetGroupedNotificationsRelatedViewsStarterPackView value)?  starterPackView,TResult? Function( UNotificationGetGroupedNotificationsRelatedViewsUnknown value)?  unknown,}){
final _that = this;
switch (_that) {
case UNotificationGetGroupedNotificationsRelatedViewsProfileViewDetailed() when profileViewDetailed != null:
return profileViewDetailed(_that);case UNotificationGetGroupedNotificationsRelatedViewsBlockedPost() when blockedPost != null:
return blockedPost(_that);case UNotificationGetGroupedNotificationsRelatedViewsGeneratorView() when generatorView != null:
return generatorView(_that);case UNotificationGetGroupedNotificationsRelatedViewsNotFoundPost() when notFoundPost != null:
return notFoundPost(_that);case UNotificationGetGroupedNotificationsRelatedViewsPostView() when postView != null:
return postView(_that);case UNotificationGetGroupedNotificationsRelatedViewsStarterPackView() when starterPackView != null:
return starterPackView(_that);case UNotificationGetGroupedNotificationsRelatedViewsUnknown() when unknown != null:
return unknown(_that);case _:
  return null;

}
}