recover

inline fun <R> AsyncResult<R>.recover(transform: (Error) -> R): AsyncResult<R>

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

If this is a Success, Loading, or NotStarted, returns this unchanged. If this is an Error, applies transform and returns Success with the result.

Example:

val result: AsyncResult<Int> = Error(Exception("Failed"))
val recovered = result.recover { 0 } // Success(0)

Return

AsyncResult with the error recovered to success, or unchanged if already successful

Parameters

transform

Function to convert an Error to a success value