Package-level declarations

Types

Link copied to clipboard
sealed interface ClerkResult<out T : Any, out E : Any>

ClerkResult is a sealed interface used throughout the Clerk SDK to represent the result of an API call. It provides a type-safe and non-exceptional way to handle either a successful response with data or a failure with error details.

Properties

Link copied to clipboard

Convenience function to extract the long error message from a ClerkResult.Failure.

Functions

Link copied to clipboard

Returns the encapsulated Throwable exception if this is a failure.

Link copied to clipboard
inline fun <T : Any, R : Any, E : Any> ClerkResult<T, E>.flatMap(transform: (value: T) -> ClerkResult<R, E>): ClerkResult<R, E>

Returns a new ClerkResult by applying transform to the value of a ClerkResult.Success, or returns the original ClerkResult.Failure if this is a failure.

Link copied to clipboard
inline fun <T : Any, E : Any, C> ClerkResult<T, E>.fold(onSuccess: (value: T) -> C, onFailure: (failure: ClerkResult.Failure<E>) -> C): C

Transforms an ClerkResult into a C value.

Link copied to clipboard
inline fun <T : Any, E : Any> ClerkResult<T, E>.onFailure(action: (failure: ClerkResult.Failure<E>) -> Unit): ClerkResult<T, E>

Performs the given action on the encapsulated ClerkResult.Failure if this instance represents failure. Returns the original ClerkApiResult unchanged.

Link copied to clipboard
inline fun <T : Any, E : Any> ClerkResult<T, E>.onFailureType(errorType: ClerkResult.Failure.ErrorType, action: (failure: ClerkResult.Failure<E>) -> Unit): ClerkResult<T, E>

Performs the given action on the encapsulated failure if this instance represents a failure with the specified error type. Returns the original ClerkApiResult unchanged.

Link copied to clipboard
inline fun <T : Any, E : Any> ClerkResult<T, E>.onSuccess(action: (value: T) -> Unit): ClerkResult<T, E>

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

Link copied to clipboard

Convenience function to extract the first error message from a ClerkResult.Failure containing a ClerkErrorResponse. Returns null if the error is not a ClerkErrorResponse or if there are no error messages.

Link copied to clipboard
inline fun <T : Any, E : Any> ClerkResult<T, E>.successOrElse(defaultValue: (failure: ClerkResult.Failure<E>) -> T): T

If ClerkResult.Success, returns the underlying T value. Otherwise, returns the result of the defaultValue function.

Link copied to clipboard
inline fun <T : Any, E : Any> ClerkResult<T, E>.successOrNothing(body: (failure: ClerkResult.Failure<E>) -> Nothing): T

If ClerkResult.Success, returns the underlying T value. Otherwise, calls body with the failure, which can either throw an exception or return early (since this function is inline).

Link copied to clipboard
fun <T : Any, E : Any> ClerkResult<T, E>.successOrNull(): T?

If ClerkResult.Success, returns the underlying T value. Otherwise, returns null.

Link copied to clipboard
inline suspend fun <T : Any, R : Any, E : Any> ClerkResult<T, E>.suspendingFlatMap(transform: suspend (value: T) -> ClerkResult<R, E>): ClerkResult<R, E>

Returns a new ClerkResult by applying transform to the value of a ClerkResult.Success, or returns the original ClerkResult.Failure if this is a failure.

Link copied to clipboard
inline suspend fun <T : Any, E : Any, C> ClerkResult<T, E>.suspendingFold(noinline onSuccess: suspend (value: T) -> C, noinline onFailure: (failure: ClerkResult.Failure<E>) -> C): C

Transforms an ClerkResult into a C value.