Skip to content

Instantly share code, notes, and snippets.

@markchristopherng
Last active September 10, 2018 22:57
Show Gist options
  • Save markchristopherng/380aa7d09555c69332c7297757c65197 to your computer and use it in GitHub Desktop.
Save markchristopherng/380aa7d09555c69332c7297757c65197 to your computer and use it in GitHub Desktop.
Resource show loading state
/**
* A generic class that holds a value with its loading status.
* @param <T>
</T> */
data class Resource<out T>(val status: Status, val data: T?, val message: String?) {
companion object {
fun <T> success(data: T?): Resource<T> {
return Resource(SUCCESS, data, null)
}
fun <T> error(msg: String, data: T?): Resource<T> {
return Resource(ERROR, data, msg)
}
fun <T> loading(data: T?): Resource<T> {
return Resource(LOADING, data, null)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment