mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2026-10-25 14:17:14 +00:00
add safe wrapper
This commit is contained in:
1 parent
023657558e
commit
43fe06206a
4 files changed
+22
No files matched your search
@@ -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"/>
|
||||
Reference in new issue
Block a user