-
-
Save MaxMichel2/b2ce86c0208b1c1cecb9c28be4f1f1e2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed class Result<out D, out E> { | |
data class Success<out D>(val data: D) : Result<D, Nothing>() | |
data class Error(val error: AppError) : Result<Nothing, Nothing>() | |
data class BusinessRuleError<out E>(val error: E) : Result<Nothing, E>() | |
data object Loading : Result<Nothing, Nothing>() | |
fun isSuccessful() = this is Success | |
fun hasFailed() = this is Error || this is BusinessRuleError<*> | |
fun isLoading() = this is Loading | |
override fun toString(): String { | |
return when (this) { | |
is Success<*> -> "Success[data=$data]" | |
is Error -> "Error[exception=$error]" | |
is BusinessRuleError<*> -> "BusinessRuleError[error=$error]" | |
Loading -> "Loading" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment