diff --git a/auth/src/commonMain/kotlin/com/liftric/base/Result.kt b/auth/src/commonMain/kotlin/com/liftric/base/Result.kt index 4b89b14..a8b5016 100644 --- a/auth/src/commonMain/kotlin/com/liftric/base/Result.kt +++ b/auth/src/commonMain/kotlin/com/liftric/base/Result.kt @@ -34,6 +34,15 @@ class Result constructor(val value: Any?) { } } +fun Result<*>.throwOnFailure() { + if (value is Result.Failure) throw value.exception +} + +inline fun Result.getOrThrow(): T { + throwOnFailure() + return value as T +} + inline fun Result.onFailure(action: (exception: Throwable) -> Unit): Result { exceptionOrNull()?.let { action(it) } return this