Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Wrapper class for Data and Status
/**
* @author Yogesh Paliyal
* Created Date : 15 October 2020
*/
data class Resource<out T>(val status: Status, val data: T?, val message: String?) {
companion object {
fun <T> success(data: T?, message: String?= ""): Resource<T> {
return Resource(Status.SUCCESS, data, message)
}
fun <T> create(status: Status,data: T?, message: String?= ""): Resource<T> {
return Resource(status, data, message)
}
fun <T> error(msg: String?, data: T? = null): Resource<T> {
return Resource(Status.ERROR, data, msg)
}
fun <T> loading(data: T? = null): Resource<T> {
return Resource(Status.LOADING, data, null)
}
}
}
/**
* @author Yogesh Paliyal
* Created Date : 15 October 2020
*/
enum class Status {
SUCCESS,
ERROR,
LOADING
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment