Created
November 25, 2020 21:31
-
-
Save SimoneLeoni1987/56588196f2da34eaa5d6542dc968796d to your computer and use it in GitHub Desktop.
[Kotlin] Resource data class
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