diff --git a/common-domain/src/main/java/com/paulrybitskyi/gamedge/common/domain/common/extensions/FlowExtensions.kt b/common-domain/src/main/java/com/paulrybitskyi/gamedge/common/domain/common/extensions/FlowExtensions.kt index da90c0ce2..5fd983cef 100644 --- a/common-domain/src/main/java/com/paulrybitskyi/gamedge/common/domain/common/extensions/FlowExtensions.kt +++ b/common-domain/src/main/java/com/paulrybitskyi/gamedge/common/domain/common/extensions/FlowExtensions.kt @@ -16,8 +16,6 @@ package com.paulrybitskyi.gamedge.common.domain.common.extensions -import com.github.michaelbull.result.Err -import com.github.michaelbull.result.Ok import com.github.michaelbull.result.Result import com.github.michaelbull.result.map import com.github.michaelbull.result.mapEither @@ -38,9 +36,9 @@ fun Flow>.onEachFailure(action: suspend (Error) -> Unit): Fl } fun Flow>.resultOrError(): Flow { - return map { - if (it is Ok) return@map it.value - if (it is Err) throw DomainException(it.error) + return map { result -> + if (result.isOk) return@map result.value + if (result.isErr) throw DomainException(result.error) error("The result is neither Ok nor Err.") } diff --git a/common-domain/src/main/java/com/paulrybitskyi/gamedge/common/domain/common/extensions/ResultExtensions.kt b/common-domain/src/main/java/com/paulrybitskyi/gamedge/common/domain/common/extensions/ResultExtensions.kt index 0572a4358..3fdcb950e 100644 --- a/common-domain/src/main/java/com/paulrybitskyi/gamedge/common/domain/common/extensions/ResultExtensions.kt +++ b/common-domain/src/main/java/com/paulrybitskyi/gamedge/common/domain/common/extensions/ResultExtensions.kt @@ -20,12 +20,12 @@ import com.github.michaelbull.result.Err import com.github.michaelbull.result.Ok import com.github.michaelbull.result.Result -fun T.asSuccess(): Ok = Ok(this) +fun T.asSuccess(): Result = Ok(this) -fun T.asFailure(): Err = Err(this) +fun T.asFailure(): Result = Err(this) suspend fun Result.onSuccess(action: suspend (V) -> Unit): Result { - if (this is Ok) { + if (isOk) { action(value) } @@ -33,7 +33,7 @@ suspend fun Result.onSuccess(action: suspend (V) -> Unit): Result Result.onFailure(action: suspend (E) -> Unit): Result { - if (this is Err) { + if (isErr) { action(error) }