add safe wrapper
This commit is contained in:
parent
023657558e
commit
43fe06206a
|
@ -0,0 +1,7 @@
|
|||
plugins {
|
||||
id "org.jetbrains.kotlin.multiplatform"
|
||||
id "org.jetbrains.kotlin.plugin.serialization"
|
||||
id "com.android.library"
|
||||
}
|
||||
|
||||
apply from: "$mppProjectWithSerializationPresetPath"
|
|
@ -0,0 +1,13 @@
|
|||
package dev.inmo.micro_utils.safe_wrapper
|
||||
|
||||
interface SafeWrapper<T> {
|
||||
fun <R> safe (block: T.() -> R): Result<R> = unsafeTarget().runCatching(block)
|
||||
fun <R> unsafe(block: T.() -> R): R = unsafeTarget().block()
|
||||
fun unsafeTarget(): T
|
||||
|
||||
class Default<T>(private val t: T) : SafeWrapper<T> { override fun unsafeTarget(): T = t }
|
||||
|
||||
companion object {
|
||||
operator fun <T> invoke(t: T) = Default(t)
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
<manifest package="dev.inmo.micro_utils.safe_wrapper"/>
|
|
@ -4,6 +4,7 @@ String[] includes = [
|
|||
":common",
|
||||
":common:compose",
|
||||
":matrix",
|
||||
":safe_wrapper",
|
||||
":crypto",
|
||||
":koin",
|
||||
":selector:common",
|
||||
|
|
Loading…
Reference in New Issue