maybeMap<TResult extends Object?> method

  1. @optionalTypeArgs
TResult maybeMap<TResult extends Object?>({
  1. TResult default_(
    1. BotCommandScopeDefault value
    )?,
  2. TResult allPrivateChats(
    1. BotCommandScopeAllPrivateChats value
    )?,
  3. TResult allGroupChats(
    1. BotCommandScopeAllGroupChats value
    )?,
  4. TResult allChatAdministrators(
    1. BotCommandScopeAllChatAdministrators value
    )?,
  5. TResult chat(
    1. BotCommandScopeChat value
    )?,
  6. TResult chatAdministrators(
    1. BotCommandScopeChatAdministrators value
    )?,
  7. TResult chatMember(
    1. BotCommandScopeChatMember value
    )?,
  8. 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(BotCommandScopeDefault value)? default_,
  TResult Function(BotCommandScopeAllPrivateChats value)? allPrivateChats,
  TResult Function(BotCommandScopeAllGroupChats value)? allGroupChats,
  TResult Function(BotCommandScopeAllChatAdministrators value)?
  allChatAdministrators,
  TResult Function(BotCommandScopeChat value)? chat,
  TResult Function(BotCommandScopeChatAdministrators value)?
  chatAdministrators,
  TResult Function(BotCommandScopeChatMember value)? chatMember,
  required TResult orElse(),
}) {
  final _that = this;
  switch (_that) {
    case BotCommandScopeDefault() when default_ != null:
      return default_(_that);
    case BotCommandScopeAllPrivateChats() when allPrivateChats != null:
      return allPrivateChats(_that);
    case BotCommandScopeAllGroupChats() when allGroupChats != null:
      return allGroupChats(_that);
    case BotCommandScopeAllChatAdministrators()
        when allChatAdministrators != null:
      return allChatAdministrators(_that);
    case BotCommandScopeChat() when chat != null:
      return chat(_that);
    case BotCommandScopeChatAdministrators() when chatAdministrators != null:
      return chatAdministrators(_that);
    case BotCommandScopeChatMember() when chatMember != null:
      return chatMember(_that);
    case _:
      return orElse();
  }
}