Skip to content

Instantly share code, notes, and snippets.

@Azooz2014
Created February 26, 2022 11:31
Show Gist options
  • Save Azooz2014/154a0d2983c881c3846f178dffb6a5c6 to your computer and use it in GitHub Desktop.
Save Azooz2014/154a0d2983c881c3846f178dffb6a5c6 to your computer and use it in GitHub Desktop.
Generic wrapper class for handling states when retriving data from API or local databases.
sealed class Resource<T>(val data: T? = null, val message: String? = null){
class Success<T>(data: T) : Resource<T>(data)
class Loading<T>(data: T? = null) : Resource<T>(data)
class Error<T>(data: T? = null, message: String) : Resource<T> (data, message)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment