Skip to content

Instantly share code, notes, and snippets.

@nicolacaferra
Created October 21, 2022 15:28
Show Gist options
  • Save nicolacaferra/8e72b950ee04a12c5becf81e0f6ef92b to your computer and use it in GitHub Desktop.
Save nicolacaferra/8e72b950ee04a12c5becf81e0f6ef92b to your computer and use it in GitHub Desktop.
State.kt
data class State<out T>(val status: Status, val data: T?, val message: String?) {
companion object {
fun <T> success(data: T?): State<T> {
return State(Status.SUCCESS, data, null)
}
fun <T> empty(): State<T> {
return State(Status.SUCCESS, null, null)
}
fun <T> error(msg: String?): State<T> {
return State(Status.ERROR, null, msg)
}
fun <T> loading(): State<T> {
return State(Status.LOADING, null, null)
}
}
}
enum class Status {
SUCCESS,
ERROR,
LOADING
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment