Fixed unused exceptionOrNull result in map/mapCatching

(replaced with isSuccess check)
This commit is contained in:
Roman Elizarov
2018-09-10 15:33:17 +03:00
parent 73907106e9
commit 1f675c8a74
@@ -227,8 +227,8 @@ public inline fun <R, T> Result<T>.map(transform: (value: T) -> R): Result<R> {
contract { contract {
callsInPlace(transform, InvocationKind.AT_MOST_ONCE) callsInPlace(transform, InvocationKind.AT_MOST_ONCE)
} }
return when(val exception = exceptionOrNull()) { return when {
null -> Result.success(transform(value as T)) isSuccess -> Result.success(transform(value as T))
else -> Result(value) else -> Result(value)
} }
} }
@@ -243,8 +243,8 @@ public inline fun <R, T> Result<T>.map(transform: (value: T) -> R): Result<R> {
*/ */
@InlineOnly @InlineOnly
public inline fun <R, T> Result<T>.mapCatching(transform: (value: T) -> R): Result<R> { public inline fun <R, T> Result<T>.mapCatching(transform: (value: T) -> R): Result<R> {
return when(val exception = exceptionOrNull()) { return when {
null -> runCatching { transform(value as T) } isSuccess -> runCatching { transform(value as T) }
else -> Result(value) else -> Result(value)
} }
} }