try Recover
Transform exception into value.
Success ->
returns
the original caller.Failure ->wraps&
returns
the result of onFailure transformation.If onFailure throws an exception, it will be caught & wrapped by resultOf.
This is the resultOf alternative to Result.recoverCatching.
resultOf { 4 } // KotlinResult.success(4)
.tryRecover { Unit } // No Change - KotlinResult.success(4)
.andThen { throw FileNotFoundException("test") } // KotlinResult.failure(FileNotFoundException("test"))
.tryRecover { 7 } // KotlinResult.success(7)
Content copied to clipboard