diff --git a/libraries/stdlib/coroutines/src/kotlin/Result.kt b/libraries/stdlib/coroutines/src/kotlin/Result.kt index 79ebad67add..7f2f9ae4c40 100644 --- a/libraries/stdlib/coroutines/src/kotlin/Result.kt +++ b/libraries/stdlib/coroutines/src/kotlin/Result.kt @@ -227,8 +227,8 @@ public inline fun Result.map(transform: (value: T) -> R): Result { contract { callsInPlace(transform, InvocationKind.AT_MOST_ONCE) } - return when(val exception = exceptionOrNull()) { - null -> Result.success(transform(value as T)) + return when { + isSuccess -> Result.success(transform(value as T)) else -> Result(value) } } @@ -243,8 +243,8 @@ public inline fun Result.map(transform: (value: T) -> R): Result { */ @InlineOnly public inline fun Result.mapCatching(transform: (value: T) -> R): Result { - return when(val exception = exceptionOrNull()) { - null -> runCatching { transform(value as T) } + return when { + isSuccess -> runCatching { transform(value as T) } else -> Result(value) } }