Created
November 14, 2022 02:57
-
-
Save cse-ariful/f765ca635b6282fc6a6176925c7638ac to your computer and use it in GitHub Desktop.
Sealed class to pass different states from a repository implementation or saving different state of a variable. Very useful when working with network calls or any other data source or single source of truth principle.
This file contains 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 ResultData<out T> { | |
object Loading : ResultData<Nothing>() | |
data class Success<out T>(val data: T) : ResultData<T>() | |
data class Error(val throwable: Exception? = null, val message: String? = null) : | |
ResultData<Nothing>() | |
fun isLoading() = this is Loading | |
fun isSuccess() = this is Success | |
fun isError() = this is Error | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment