map<TResult extends Object?> method

  1. @optionalTypeArgs
TResult map<TResult extends Object?>({
  1. required TResult photo(
    1. InputMediaPhoto value
    ),
  2. required TResult document(
    1. InputMediaDocument value
    ),
  3. required TResult animation(
    1. InputMediaAnimation value
    ),
  4. required TResult audio(
    1. InputMediaAudio value
    ),
  5. required TResult video(
    1. InputMediaVideo 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(InputMediaPhoto value) photo,
  required TResult Function(InputMediaDocument value) document,
  required TResult Function(InputMediaAnimation value) animation,
  required TResult Function(InputMediaAudio value) audio,
  required TResult Function(InputMediaVideo value) video,
}) {
  final _that = this;
  switch (_that) {
    case InputMediaPhoto():
      return photo(_that);
    case InputMediaDocument():
      return document(_that);
    case InputMediaAnimation():
      return animation(_that);
    case InputMediaAudio():
      return audio(_that);
    case InputMediaVideo():
      return video(_that);
  }
}