map<TResult extends Object?> method

  1. @optionalTypeArgs
TResult map<TResult extends Object?>({
  1. required TResult default_(
    1. BotCommandScopeDefault value
    ),
  2. required TResult allPrivateChats(
    1. BotCommandScopeAllPrivateChats value
    ),
  3. required TResult allGroupChats(
    1. BotCommandScopeAllGroupChats value
    ),
  4. required TResult allChatAdministrators(
    1. BotCommandScopeAllChatAdministrators value
    ),
  5. required TResult chat(
    1. BotCommandScopeChat value
    ),
  6. required TResult chatAdministrators(
    1. BotCommandScopeChatAdministrators value
    ),
  7. required TResult chatMember(
    1. BotCommandScopeChatMember value
    ),
})

A switch-like method, using callbacks.

Callbacks receives the raw object, upcasted. It is equivalent to doing:

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

Implementation

@optionalTypeArgs
TResult map<TResult extends Object?>({
  required TResult Function(BotCommandScopeDefault value) default_,
  required TResult Function(BotCommandScopeAllPrivateChats value)
  allPrivateChats,
  required TResult Function(BotCommandScopeAllGroupChats value) allGroupChats,
  required TResult Function(BotCommandScopeAllChatAdministrators value)
  allChatAdministrators,
  required TResult Function(BotCommandScopeChat value) chat,
  required TResult Function(BotCommandScopeChatAdministrators value)
  chatAdministrators,
  required TResult Function(BotCommandScopeChatMember value) chatMember,
}) {
  final _that = this;
  switch (_that) {
    case BotCommandScopeDefault():
      return default_(_that);
    case BotCommandScopeAllPrivateChats():
      return allPrivateChats(_that);
    case BotCommandScopeAllGroupChats():
      return allGroupChats(_that);
    case BotCommandScopeAllChatAdministrators():
      return allChatAdministrators(_that);
    case BotCommandScopeChat():
      return chat(_that);
    case BotCommandScopeChatAdministrators():
      return chatAdministrators(_that);
    case BotCommandScopeChatMember():
      return chatMember(_that);
  }
}