try Recover Of
inline suspend fun <Ok, ErrorIn, ErrorOut> Outcome<Ok, ErrorIn>.tryRecoverOf(catch: (throwable: Throwable) -> Outcome<Ok, ErrorOut> = ::rethrow, scope: RaiseScope<ErrorOut> = DefaultRaiseScope(), failure: RaiseScope<ErrorOut>.(ErrorIn) -> Ok): Outcome<Ok, ErrorOut>
Transforms a Failure into a Success, wrapping the result with outcomeOf error-catching semantics.
Success — returned unchanged.
If failure throws, the exception is re-encapsulated or re-thrown via catch.
This is the outcomeOf alternative to recover — it catches exceptions rather than letting them propagate.
outcomeOf { 4 } // Success(4)
.tryRecoverOf { Unit } // No change — Success(4)
.andThenOf { throw FileNotFoundException("test") } // Failure(FileNotFoundException("test"))
.tryRecoverOf { 7 } // Success(7)Content copied to clipboard
Parameters
Ok
The Success value type.
Error In
The incoming Failure error type.
Error Out
The outgoing Failure error type after transformation.
catch
Handles exceptions thrown by failure. Defaults to rethrowing via rethrow.
scope
The RaiseScope used to raise typed errors.
failure
The transform applied to the Failure error value.