Created
July 13, 2020 01:41
-
-
Save sberoch/30c2bd6a39f56d762caff5e155677f37 to your computer and use it in GitHub Desktop.
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
data class Resource<out T>(val status: Status, val data: T?, val message: String?) { | |
enum class Status { | |
SUCCESS, | |
ERROR, | |
LOADING | |
} | |
companion object { | |
fun <T> success(data: T): Resource<T> { | |
return Resource(Status.SUCCESS, data, null) | |
} | |
fun <T> error(message: String, data: T? = null): Resource<T> { | |
return Resource(Status.ERROR, data, message) | |
} | |
fun <T> loading(data: T? = null): Resource<T> { | |
return Resource(Status.LOADING, data, null) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment