KmmResult

@ObjCName(swiftName = "KmmResult", name = "KmmResult")
class KmmResult<out T>(source)

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)

Trying to create a failure case re-throws any fatal exceptions, such as OutOfMemoryError. Relies on Arrow's nonFatalOrThrow internally.

Constructors

Link copied to clipboard
constructor(value: T)

Creates a success result from the given value

constructor(failure: Throwable)

Creates a failure result from the given failure Trying to create a failure case re-throws any fatal exceptions, such as OutOfMemoryError. Relies on Arrow's nonFatalOrThrow internally.

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Returns true if this instance represents a failed outcome. In this case isSuccess returns false.

Link copied to clipboard

Returns true if this instance represents a successful outcome. In this case isFailure returns false.

Functions

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard

Returns the encapsulated Throwable exception if this instance represents failure or null if it is success.

Link copied to clipboard
inline fun <R> fold(onSuccess: (value: T) -> R, onFailure: (exception: Throwable) -> R): R

Returns the result of onSuccess for the encapsulated value if this instance represents success or the result of onFailure function for the encapsulated Throwable exception if it is failure.

Link copied to clipboard
inline fun getOrElse(onFailure: (exception: Throwable) -> @UnsafeVariance T): T

Returns the encapsulated value if this instance represents success or the result of onFailure function for the encapsulated Throwable exception if it is failure.

Link copied to clipboard
fun getOrNull(): T?

Returns the encapsulated value if this instance represents success or null if it is failure.

Link copied to clipboard
fun getOrThrow(): T

Returns the encapsulated value if this instance represents success or throws the encapsulated Throwable exception if it is failure.

Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
inline fun <R> map(block: (T) -> R): KmmResult<R>

Transforms this KmmResult's success-case according to block and leaves the failure case untouched

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

Returns the encapsulated result of the given block function applied to the encapsulated value if this instance represents success or the original encapsulated Throwable exception if it is failure.

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

Transforms this KmmResult's failure-case according to block and leaves the success case untouched

Link copied to clipboard
inline fun <R> onFailure(block: (error: Throwable) -> R): KmmResult<T>

singular version of fold's onFailure

Link copied to clipboard
inline fun <R> onSuccess(block: (value: T) -> R): KmmResult<T>

singular version of fold's onSuccess

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
open override fun toString(): String
Link copied to clipboard
inline fun <R> transform(block: (T) -> KmmResult<R>): KmmResult<R>

Transforms this KmmResult into a KmmResult of different success type according to block and leaves the failure case untouched. Avoids nested KmmResults.

Link copied to clipboard
fun unwrap(): Result<T>

Returns a Result equivalent of this KmmResult