Skip to main content

ResultCompat

ResultCompat is a class defined for Java compatibility and provides functionality similar to kotlin Result<T>.

Summary

Public constructors

java-static ResultCompat<Boolean>

<T> success(value: Class<T!>)

Stores the given data as success data and returns a ResultCompat object.

java-static ResultCompat<Boolean>

failure(throwable: Throwable)

Stores the given Throwable as a failure error and returns a ResultCompat object.

Public functions
T?
getOrNull()

Returns T if success data exists; otherwise, returns null.

T
getOrThrow()

Returns T if success data exists; otherwise, throws an exception.

Throwable ?

exceptionOrNull()

If a failure error exists, returns Throwable; otherwise, returns null.

ResultCompat<Boolean>

<T> fold(onSuccess: (T) -> Unit, onFailure: (Throwable) -> Unit)

Registers functions to handle success and failure.

ResultCompat<Boolean>

<T> onSuccess(action: (T) -> Unit)

Registers a function to handle success.

ResultCompat<Boolean>

<T> onFailure(action: (Throwable) -> Unit)

Registers a function to handle failure.

Public properties
Boolean
val isFailure: Boolean

Returns true if an error occurred.

Boolean
val isSuccess: Boolean

Returns true if successful.


Public methods

getOrNull()
fun <T> getOrNull(): T?

If a success data exists, returns T; otherwise, returns null.

Returns

T?

Success data

getOrThrow()
fun <T> getOrThrow(): T

If a success data exists, returns T; otherwise, returns null.

Returns

T

Success data

exceptionOrNull()
fun <T> exceptionOrNull(): Throwable?

If a failure error exists, returns Throwable; otherwise, returns null.

Returns

Throwable ?

Failure error

fold()
fun <T> fold(onSuccess: (T) -> Unit, onFailure: (Throwable) -> Unit): ResultCompat<T>

Registers functions to handle success and failure.

Parameters

(T) -> Unit

Lambda to handle success

(Throwable) -> Unit

Lambda to handle failure
Returns

ResultCompat<Boolean>

ResultCompat

onSuccess()
fun <T> onSuccess(action: (T) -> Unit): ResultCompat<T>

Registers a function to handle success.

Parameters

(T) -> Unit

Lambda to handle success
Returns

ResultCompat<Boolean>

ResultCompat

onFailure()
fun <T> onFailure(action: (Throwable) -> Unit): ResultCompat<T>

Registers a function to handle failure.

Parameters

(Throwable) -> Unit

Lambda to handle failure
Returns

ResultCompat<Boolean>

ResultCompat