Success

class Success<out S, out F>(val value: S) : Try<S, F>

Constructors

Link copied to clipboard
constructor(value: S)

Properties

Link copied to clipboard
open override val isFailure: Boolean
Link copied to clipboard
open override val isSuccess: Boolean
Link copied to clipboard
val value: S

Functions

Link copied to clipboard
fun <S, F> Try<S, F>.checkSuccess(): S

Returns value in case of success and throws an IllegalStateException in case of failure.

Link copied to clipboard
inline suspend fun <R> Try<ByteArray, ReadError>.decodeOrElse(decode: (value: ByteArray) -> Try<R, DecodeError>, recover: (DecodeError.Decoding) -> R): Try<R, ReadError>
Link copied to clipboard
inline suspend fun <R> Try<ByteArray, ReadError>.decodeOrNull(decode: (value: ByteArray) -> Try<R, DecodeError>): R?
Link copied to clipboard
open override fun failureOrNull(): F?

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

Link copied to clipboard
inline fun <R, S, F> Try<S, F>.flatMap(transform: (value: S) -> Try<R, F>): Try<R, F>

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

Link copied to clipboard
inline fun <R> fold(onSuccess: (value: S) -> R, onFailure: (exception: F) -> 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 value if it is failure.

Link copied to clipboard
fun <R, S : R, F> Try<S, F>.getOrDefault(defaultValue: R): R

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

Link copied to clipboard
inline fun <R, S : R, F> Try<S, F>.getOrElse(onFailure: (exception: F) -> R): R

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

Link copied to clipboard
open override fun getOrNull(): S?

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

Link copied to clipboard
fun <S, F : Throwable> Try<S, F>.getOrThrow(): S

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

Link copied to clipboard
inline fun <R> map(transform: (value: S) -> R): Try<R, F>

Returns the encapsulated result of the given transform 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 <F> mapFailure(transform: (value: F) -> F): Try<S, F>

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

Link copied to clipboard
inline fun onFailure(action: (exception: F) -> Unit): Try<S, F>

Performs the given action on the encapsulated value if this instance represents failure. Returns the original Try unchanged.

Link copied to clipboard
inline fun onSuccess(action: (value: S) -> Unit): Try<S, F>

Performs the given action on the encapsulated value if this instance represents success. Returns the original Try unchanged.

Link copied to clipboard
inline fun <R, S : R, F, T> Try<S, F>.tryRecover(transform: (exception: F) -> Try<R, T>): Try<R, T>

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