All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.SafeWrapper.kt Maven / Gradle / Ivy

The newest version!
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)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy