Skip to content

Instantly share code, notes, and snippets.

@cse-ariful
Created November 14, 2022 02:57
Show Gist options
  • Save cse-ariful/f765ca635b6282fc6a6176925c7638ac to your computer and use it in GitHub Desktop.
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.
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