commonMain.SafeWrapper.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of micro_utils.safe_wrapper-jvm Show documentation
Show all versions of micro_utils.safe_wrapper-jvm Show documentation
It is set of projects with micro tools for avoiding of routines coding
package dev.inmo.micro_utils.safe_wrapper
import dev.inmo.micro_utils.coroutines.runCatchingSafely
interface SafeWrapper {
fun safe(block: T.() -> R): Result = unsafeTarget().runCatching(block)
fun unsafe(block: T.() -> R): R = unsafeTarget().block()
suspend fun safeS(block: suspend T.() -> R): Result = unsafeTarget().runCatchingSafely(block = block)
suspend fun unsafeS(block: suspend T.() -> R): R = unsafeTarget().block()
fun unsafeTarget(): T
class Default(private val t: T) : SafeWrapper { override fun unsafeTarget(): T = t }
companion object {
operator fun invoke(t: T) = Default(t)
}
}