mapOrNull<TResult extends Object?> method
- @optionalTypeArgs
- TResult? photo(
- InputMediaPhoto value
- TResult? document(
- InputMediaDocument value
- TResult? animation(
- InputMediaAnimation value
- TResult? audio(
- InputMediaAudio value
- TResult? video(
- InputMediaVideo 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(InputMediaPhoto value)? photo,
TResult? Function(InputMediaDocument value)? document,
TResult? Function(InputMediaAnimation value)? animation,
TResult? Function(InputMediaAudio value)? audio,
TResult? Function(InputMediaVideo value)? video,
}) {
final _that = this;
switch (_that) {
case InputMediaPhoto() when photo != null:
return photo(_that);
case InputMediaDocument() when document != null:
return document(_that);
case InputMediaAnimation() when animation != null:
return animation(_that);
case InputMediaAudio() when audio != null:
return audio(_that);
case InputMediaVideo() when video != null:
return video(_that);
case _:
return null;
}
}