toKotlinResult

inline fun <T> T.toKotlinResult(predicate: T.() -> Boolean = { this !is Throwable }, failure: (T) -> Throwable = { value: T -> value.asThrowable { "${it}.asKotlinResult() failed predicate test!" } }): KotlinResult<T>

Wraps this value as a KotlinResult based on predicate.

By default, any value that is not a Throwable is treated as a success.

Parameters

T

The type of the receiver value.

predicate

Determines whether the value represents a success. Defaults to { this !is Throwable }.

failure

Produces the Throwable when predicate returns false.


Converts an Outcome to a KotlinResult.

Success values are wrapped with kotlinSuccess. Failure values are converted to Throwable and wrapped with kotlinFailure.