From 0b85cc2aad1862489c101958ac0c41adf9341d24 Mon Sep 17 00:00:00 2001 From: Michael Bull Date: Fri, 8 Mar 2024 20:29:41 +0000 Subject: [PATCH] Reuse runCatching in recoverCatching --- .../kotlin/com/github/michaelbull/result/Recover.kt | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Recover.kt b/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Recover.kt index 2e358a4..2618000 100644 --- a/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Recover.kt +++ b/kotlin-result/src/commonMain/kotlin/com/github/michaelbull/result/Recover.kt @@ -29,13 +29,7 @@ public inline infix fun Result.recoverCatching(transform: (E) -> V) return when (this) { is Ok -> this - is Err -> { - try { - Ok(transform(error)) - } catch (e: Throwable) { - Err(e) - } - } + is Err -> runCatching { transform(error) } } }