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. Relies on Arrow's nonFatalOrThrow internally.

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

Non-fatal-only-catching version of stdlib's runCatching (calling the specified function block with this value as its receiver), directly returning a KmmResult -- Re-throws any fatal exceptions, such as OutOfMemoryError. Relies on Arrow's nonFatalOrThrow internally.

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> wrapping(asA: (String?, Throwable) -> E, block: () -> R): KmmResult<R>

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> T.wrapping(asA: (String?, Throwable) -> E, block: T.() -> R): KmmResult<R>

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