to Kotlin Result
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.
If predicate returns
true, wraps as Result.success.If predicate returns
false, calls failure to produce a Throwable and wraps as Result.failure.
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 }.
Converts an Outcome to a KotlinResult.
Success values are wrapped with kotlinSuccess. Failure values are converted to Throwable and wrapped with kotlinFailure.