Package-level declarations

Types

Link copied to clipboard
@ObjCName(swiftName = "KmmResult", name = "KmmResult")
class KmmResult<out T>

Swift-Friendly variant of stdlib's Result. For easy use under iOS, we need a class like Result that is not a value class (which is unsupported in Kotlin/Native)

Functions

Link copied to clipboard
inline fun <T> catching(block: () -> T): KmmResult<T>

Non-fatal-only-catching version of stdlib's runCatching, directly returning a KmmResult -- Re-throws any fatal exceptions, such as OutOfMemoryError. Re-implements Arrow's nonFatalOrThrow logic to avoid a dependency on Arrow for a single function.

Link copied to clipboard
inline fun <T, R> R.catching(block: R.() -> T): KmmResult<T>
Link copied to clipboard
inline fun <E : Throwable, T> catchingAs(a: (Throwable) -> E, block: () -> T): KmmResult<T>

inline fun <E : Throwable, T> catchingAs(a: (String?, Throwable) -> E, block: () -> T): KmmResult<T>

Runs the specified function block, returning a KmmResult. Any non-fatal exception will be wrapped as the specified exception, unless it is already the specified type.

Link copied to clipboard
inline fun <E : Throwable, T, R> R.catchingAs(a: (Throwable) -> E, block: R.() -> T): KmmResult<T>
inline fun <E : Throwable, T, R> R.catchingAs(a: (String?, Throwable) -> E, block: R.() -> T): KmmResult<T>
Link copied to clipboard
inline fun <T> catchingUnwrapped(block: () -> T): Result<T>

Non-fatal-only-catching version of stdlib's runCatching, returning a Result -- Re-throws any fatal exceptions, such as OutOfMemoryError. Re-implements Arrow's nonFatalOrThrow logic to avoid a dependency on Arrow for a single function.

Link copied to clipboard
inline fun <T, R> T.catchingUnwrapped(block: T.() -> R): Result<R>
Link copied to clipboard
inline fun <E : Throwable, T> catchingUnwrappedAs(a: (Throwable) -> E, block: () -> T): Result<T>

inline fun <E : Throwable, T> catchingUnwrappedAs(a: (String?, Throwable) -> E, block: () -> T): Result<T>

Runs the specified function block, returning a Result. Any non-fatal exception will be wrapped as the specified exception, unless it is already the specified type.

Link copied to clipboard
inline fun <E : Throwable, T, R> R.catchingUnwrappedAs(a: (Throwable) -> E, block: R.() -> T): Result<T>
inline fun <E : Throwable, T, R> R.catchingUnwrappedAs(a: (String?, Throwable) -> E, block: R.() -> T): Result<T>
Link copied to clipboard
inline fun <T> Result<T>.nonFatalOrThrow(): Result<T>

Helper to effectively convert stdlib's runCatching to behave like KmmResult's Non-fatal-only catching. I.e. any fatal exceptions are thrown. The reason this exists is that catching incurs instantiation cost. This helper hence provides the best of both worlds.

expect inline fun Throwable.nonFatalOrThrow(): Throwable

Throws any fatal exceptions. This is a re-implementation taken from Arrow's nonFatalOrThrow – to avoid a dependency on Arrow for a single function.

actual inline fun Throwable.nonFatalOrThrow(): Throwable
actual inline fun Throwable.nonFatalOrThrow(): Throwable
actual inline fun Throwable.nonFatalOrThrow(): Throwable
actual inline fun Throwable.nonFatalOrThrow(): Throwable
actual inline fun Throwable.nonFatalOrThrow(): Throwable
actual inline fun Throwable.nonFatalOrThrow(): Throwable
actual inline fun Throwable.nonFatalOrThrow(): Throwable
actual inline fun Throwable.nonFatalOrThrow(): Throwable
actual inline fun Throwable.nonFatalOrThrow(): Throwable
actual inline fun Throwable.nonFatalOrThrow(): Throwable
actual inline fun Throwable.nonFatalOrThrow(): Throwable
actual inline fun Throwable.nonFatalOrThrow(): Throwable
actual inline fun Throwable.nonFatalOrThrow(): Throwable
actual inline fun Throwable.nonFatalOrThrow(): Throwable
actual inline fun Throwable.nonFatalOrThrow(): Throwable
Link copied to clipboard
inline fun <R, T : R> KmmResult<T>.recoverCatching(block: (error: Throwable) -> R): KmmResult<R>

If this is successful, returns it. If this is failed, encapsulate the result of the provided recovery function. If the recovery function throws, the return value is a failed KmmResult.

Link copied to clipboard
inline fun <E : Throwable, R> Result<R>.wrapAs(a: (Throwable) -> E): Result<R>

inline fun <E : Throwable, T> Result<T>.wrapAs(a: (String?, Throwable) -> E): Result<T>

If the underlying Result is successful, returns it unchanged. If it failed, and the contained exception is of the specified type, returns it unchanged. Otherwise, wraps the contained exception in the specified type.

Link copied to clipboard
inline fun <E : Throwable, R> wrapping(asA: (String?, Throwable) -> E, block: () -> R): KmmResult<R>
Link copied to clipboard
inline fun <E : Throwable, T, R> R.wrapping(asA: (String?, Throwable) -> E, block: R.() -> T): KmmResult<T>