commonMain.dev.inmo.tgbotapi.extensions.utils.ClassCastsNewAny.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tgbotapi.utils-jvm Show documentation
Show all versions of tgbotapi.utils-jvm Show documentation
Additional extensions for core part of tgbotapi
@file:Suppress("NOTHING_TO_INLINE", "unused", "UNCHECKED_CAST")
package dev.inmo.tgbotapi.extensions.utils
import dev.inmo.tgbotapi.abstracts.FromUser
import dev.inmo.tgbotapi.abstracts.OptionallyFromUser
import dev.inmo.tgbotapi.abstracts.OptionallyWithUser
import dev.inmo.tgbotapi.abstracts.WithUser
import dev.inmo.tgbotapi.types.abstracts.WithOptionalLanguageCode
import dev.inmo.tgbotapi.types.message.abstracts.WithSenderChatMessage
import dev.inmo.tgbotapi.utils.PreviewFeature
@PreviewFeature
inline fun Any.ifOptionallyFromUser(block: (OptionallyFromUser) -> T) = optionallyFromUserOrNull()?.let(block)
@PreviewFeature
inline fun Any.optionallyFromUserOrNull(): OptionallyFromUser? = this as? OptionallyFromUser
@PreviewFeature
inline fun Any.optionallyFromUserOrThrow(): OptionallyFromUser = this as OptionallyFromUser
@PreviewFeature
inline fun Any.ifFromUser(block: (FromUser) -> T) = fromUserOrNull()?.let(block)
@PreviewFeature
inline fun Any.fromUserOrNull(): FromUser? = this as? FromUser
@PreviewFeature
inline fun Any.fromUserOrThrow(): FromUser = this as FromUser
@PreviewFeature
inline fun Any.ifOptionallyWithUser(block: (OptionallyWithUser) -> T) = optionallyWithUserOrNull()?.let(block)
@PreviewFeature
inline fun Any.optionallyWithUserOrNull(): OptionallyWithUser? = this as? OptionallyWithUser
@PreviewFeature
inline fun Any.optionallyWithUserOrThrow(): OptionallyWithUser = this as OptionallyWithUser
@PreviewFeature
inline fun Any.ifWithUser(block: (WithUser) -> T) = withUserOrNull()?.let(block)
@PreviewFeature
inline fun Any.withUserOrNull(): WithUser? = this as? WithUser
@PreviewFeature
inline fun Any.withUserOrThrow(): WithUser = this as WithUser
@PreviewFeature
inline fun Any.ifWithOptionalLanguageCode(block: (WithOptionalLanguageCode) -> T) =
withOptionalLanguageCodeOrNull()?.let(block)
@PreviewFeature
inline fun Any.withOptionalLanguageCodeOrNull(): WithOptionalLanguageCode? = this as? WithOptionalLanguageCode
@PreviewFeature
inline fun Any.withOptionalLanguageCodeOrThrow(): WithOptionalLanguageCode = this as WithOptionalLanguageCode
@PreviewFeature
inline fun Any.ifWithSenderChatMessage(block: (WithSenderChatMessage) -> T) =
withSenderChatMessageOrNull()?.let(block)
@PreviewFeature
inline fun Any.withSenderChatMessageOrNull(): WithSenderChatMessage? = this as? WithSenderChatMessage
@PreviewFeature
inline fun Any.withSenderChatMessageOrThrow(): WithSenderChatMessage = this as WithSenderChatMessage