bimap

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

Transforms both Success and Error cases simultaneously.

This allows you to transform the success value and error in a single operation. Loading and NotStarted states pass through unchanged.

Example:

val result: AsyncResult<Int> = Success(42)
val transformed = result.bimap(
success = { it * 2 },
error = { it.withMetadata("Calculation failed") }
) // Success(84)

val errorResult: AsyncResult<Int> = Error(Exception("Failed"))
val transformed = errorResult.bimap(
success = { it * 2 },
error = { it.withMetadata("Calculation failed") }
) // Error with added metadata

Return

AsyncResult with both success and error cases transformed

Parameters

success

Function to transform the success value

error

Function to transform the error