toErrorUnless

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.

Return

The original AsyncResult if predicate is true or not Success, otherwise an Error.

Parameters

predicate

Function that receives the success value and returns true to keep Success.

error

Optional function to create a custom Error from the success value. Defaults to Error.Empty.