Loading

Used to model in-flight operations. For example, if a request is user initiated, it'll be in this state since the user initiated it up until it's either Success or Error.

Properties

Link copied to clipboard

Returns true if the AsyncResult is Incomplete, false otherwise.

Link copied to clipboard

Returns true if the AsyncResult is Success, false otherwise.

Link copied to clipboard
open val value: Nothing?

Functions

Link copied to clipboard
inline fun <R> AsyncResult<R>.and(result: AsyncResult<R>): AsyncResult<R>

Returns the result if the receiver is Success.

Link copied to clipboard
inline fun <R, T> AsyncResult<R>.andThen(noinline transform: (R) -> AsyncResult<T>): AsyncResult<T>

Returns the transform result value if both the receiver and the transformed value are Success.

Link copied to clipboard
inline fun <R, T> AsyncResult<R>.bimap(success: (R) -> T, error: (Error) -> Error): AsyncResult<T>

Transforms both Success and Error cases simultaneously.

Link copied to clipboard
inline fun <T> Incomplete.cast(): AsyncResult<T>

Converts Loading and NotStarted to a AsyncResult of type T. This is to prevent us to having to map everything when we know we don't have a Success value, where types would actually matter.

Link copied to clipboard
inline fun <R> AsyncResult<*>.castOrError(noinline lazyMetadata: () -> Any?? = null): AsyncResult<R>

Converts the current AsyncResult to a AsyncResult of type R if the current value is of type R. If the current value is not of type R, it will return an Error.

Link copied to clipboard
@JvmName(name = "component1Pair")
inline operator fun <T> AsyncResult<Pair<T, *>>.component1(): AsyncResult<T>
@JvmName(name = "component1Triple")
inline operator fun <T> AsyncResult<Triple<T, *, *>>.component1(): AsyncResult<T>
Link copied to clipboard
@JvmName(name = "component2Pair")
inline operator fun <T> AsyncResult<Pair<*, T>>.component2(): AsyncResult<T>
@JvmName(name = "component2Triple")
inline operator fun <T> AsyncResult<Triple<*, T, *>>.component2(): AsyncResult<T>
Link copied to clipboard
@JvmName(name = "component3Triple")
inline operator fun <T> AsyncResult<Triple<*, *, T>>.component3(): AsyncResult<T>
Link copied to clipboard
inline fun <R> AsyncResult<R>.errorIdOrNull(): ErrorId?

Returns the ErrorId if the AsyncResult is Error and has an errorId, else returns null.

Link copied to clipboard
inline fun <R> AsyncResult<R>.errorOrNull(): Error?

Returns the Error itself if the AsyncResult is Error else returns null.

Link copied to clipboard

Returns the metadata value from the Error if the AsyncResult is Error, and has metadata or the requested type.

Link copied to clipboard
inline fun <R> AsyncResult<R>.expect(crossinline message: () -> Any): R

Extracts the value from the AsyncResult if it's a Success, otherwise throws an UnwrapException with the computed message in it.

Link copied to clipboard
inline fun AsyncResult<*>.expectError(crossinline message: () -> Any): Error

Extracts the value from the AsyncResult if it's an Error, otherwise throws an UnwrapException with the computed message in it.

Link copied to clipboard
inline fun AsyncResult<*>.expectErrorId(crossinline message: () -> Any): ErrorId

Extracts the ErrorId from the AsyncResult if it's an Error with an ErrorId, otherwise throws an UnwrapException with the computed message in it.

Link copied to clipboard
inline fun <M> AsyncResult<*>.expectMetadata(crossinline message: () -> Any): M

Extracts the metadata from the AsyncResult if it's an Error with the metadata of type M, otherwise throws an UnwrapException with the computed message in it.

Link copied to clipboard
inline fun AsyncResult<*>.expectThrowable(crossinline message: () -> Any): Throwable

Extracts the value from the AsyncResult if it's an Error with a Throwable in it, otherwise throws an UnwrapException with the computed message in it.

Link copied to clipboard
inline fun <R> AsyncResult<R>.filterOrError(noinline lazyMetadata: () -> Any?? = null, predicate: (R) -> Boolean): AsyncResult<R>

Returns the current AsyncResult if it matches the given predicate, or an Error if it does not.

Link copied to clipboard
inline fun <R, T> AsyncResult<R>.flatMap(transform: (R) -> AsyncResult<T>): AsyncResult<T>

Transforms the current AsyncResult to the result of transform if it's a Success, based on its contained value.

Link copied to clipboard

Unwraps the AsyncResult inside of the AsyncResult.

Link copied to clipboard
inline fun <R, T> AsyncResult<R>.fold(ifNotStarted: () -> T, ifLoading: () -> T, ifSuccess: (R) -> T, ifError: (Error) -> T): T

Generates a value of type T from any state contained in AsyncResult.

Link copied to clipboard
inline fun <R> AsyncResult<R>.getOrDefault(default: R): R

Returns the value if the AsyncResult is Success else returns the default value.

Link copied to clipboard
inline fun <R> AsyncResult<R>.getOrElse(transform: (AsyncResult<R>) -> R): R

Returns the value if the AsyncResult is Success else returns the result of the transform function.

Link copied to clipboard
inline fun <R> AsyncResult<List<R>>.getOrEmpty(): List<R>

Returns the value if the AsyncResult is Success else returns an empty list.

inline fun <K, V> AsyncResult<Map<K, V>>.getOrEmpty(): Map<K, V>

Returns the value if the AsyncResult is Success else returns an empty map.

Link copied to clipboard
inline fun <R> AsyncResult<R>.getOrNull(): R?

Returns the value if the AsyncResult is Success else returns null.

Link copied to clipboard
inline fun <R> AsyncResult<R>.getOrThrow(): R

Returns the value if the AsyncResult is Success else returns null.

Link copied to clipboard
inline fun <R, T> AsyncResult<R>.map(transform: (AsyncResult<R>) -> AsyncResult<T>): AsyncResult<T>

Transforms the current AsyncResult to the result of transform.

Link copied to clipboard
inline fun <R> AsyncResult<R>.mapError(transform: (Error) -> Error): AsyncResult<R>

Transforms the Error value, if any, via transform.

Link copied to clipboard
inline fun <R, T> AsyncResult<R>.mapSuccess(transform: (R) -> T): AsyncResult<T>

Transforms the Success value via transform. The AsyncResult will change its containing type accordingly.

Link copied to clipboard
inline fun <R> AsyncResult<R>.onError(block: (Throwable?) -> Unit): AsyncResult<R>

Runs the block when the result is Error.

Link copied to clipboard
inline fun <R, M> AsyncResult<R>.onErrorWithMetadata(block: (throwable: Throwable?, metadata: M?) -> Unit): AsyncResult<R>

Runs the block when the result is Error and has metadata of type M.

Link copied to clipboard
inline fun <R> AsyncResult<R>.onLoading(block: () -> Unit): AsyncResult<R>

Runs the block when the result is Loading.

Link copied to clipboard
inline fun <R> AsyncResult<R>.onNotStarted(block: () -> Unit): AsyncResult<R>

Runs the block when the result is NotStarted.

Link copied to clipboard
inline fun <R> AsyncResult<R>.onSuccess(block: (R) -> Unit): AsyncResult<R>

Runs the block when the value is Success.

Link copied to clipboard
inline fun <R> AsyncResult<R>.or(other: AsyncResult<R>): AsyncResult<R>

Returns other if this is an Error, otherwise returns this unchanged.

Link copied to clipboard
inline fun <R> AsyncResult<R>.orElse(transform: (Error) -> AsyncResult<R>): AsyncResult<R>

Returns the result of transform if this is an Error, otherwise returns this unchanged.

Link copied to clipboard
inline fun <R> AsyncResult<R?>.orError(noinline lazyMetadata: () -> Any?? = null): AsyncResult<R>

Transforms the type of AsyncResult from nullable to non-nullable. If the value is null, it will return an Error. It also allows adding specific metadata to disambiguate errors if necessary, via lazyMetadata.

Link copied to clipboard
inline fun <R> AsyncResult<R>.recover(transform: (Error) -> R): AsyncResult<R>

Converts an Error to a Success by applying transform to the error.

Link copied to clipboard
inline fun <R, E : Any> AsyncResult<R>.recoverIf(transform: (E) -> R): AsyncResult<R>

Converts an Error to a Success only if the error metadata matches type E.

Link copied to clipboard
Link copied to clipboard

Returns the throwable if the AsyncResult is Error else returns null.

Link copied to clipboard
inline fun <T> AsyncResult<T>.toErrorIf(predicate: (T) -> Boolean, error: (T) -> Error = { Error.Empty }): AsyncResult<T>

Converts a Success to an Error if the predicate returns true for the success value. Other states (Loading, NotStarted, Error) are returned unchanged.

Link copied to clipboard
inline fun <T> AsyncResult<T>.toErrorUnless(predicate: (T) -> Boolean, error: (T) -> Error = { Error.Empty }): AsyncResult<T>

Converts a Success to an Error if the predicate returns false for the success value. This is the inverse of toErrorIf. Other states (Loading, NotStarted, Error) are returned unchanged.

Link copied to clipboard
inline fun <R> AsyncResult<R>.unwrap(): R

Extracts the value from the AsyncResult if it's a Success, otherwise throws an UnwrapException.

Link copied to clipboard
inline fun AsyncResult<*>.unwrapError(): Error

Extracts the value from the AsyncResult if it's an Error, otherwise throws an UnwrapException.

Link copied to clipboard

Extracts the ErrorId from the AsyncResult if it's an Error with an ErrorId, otherwise throws an UnwrapException.

Link copied to clipboard
inline fun <M> AsyncResult<*>.unwrapMetadata(): M

Extracts the metadata from the AsyncResult if it's an Error with metadata of type M, otherwise throws an UnwrapException.

Link copied to clipboard

Extracts the value from the AsyncResult if it's an Error with a Throwable, otherwise throws an UnwrapException.

Link copied to clipboard
inline fun <R1, R2, T> AsyncResult<R1>.zipWith(result: AsyncResult<R2>, crossinline transform: (R1, R2) -> T): AsyncResult<T>

Combines two AsyncResults (the receiver and result) into a single one, by applying the transform to their values.

inline fun <R1, R2, R3, T> AsyncResult<R1>.zipWith(result1: AsyncResult<R2>, result2: AsyncResult<R3>, crossinline transform: (R1, R2, R3) -> T): AsyncResult<T>

Combines three AsyncResults (the receiver, result1, and result2) into a single one, by applying the transform to their values.

inline fun <R1, R2, R3, R4, T> AsyncResult<R1>.zipWith(result1: AsyncResult<R2>, result2: AsyncResult<R3>, result3: AsyncResult<R4>, crossinline transform: (R1, R2, R3, R4) -> T): AsyncResult<T>

Combines four AsyncResults (the receiver, result1, result2, and result3) into a single one, by applying the transform to their values.