Skip to content

Instantly share code, notes, and snippets.

@svsq
Created March 9, 2023 09:10
Show Gist options
  • Save svsq/bdebf1e1ac805e318cbdcbc7f3541040 to your computer and use it in GitHub Desktop.
Save svsq/bdebf1e1ac805e318cbdcbc7f3541040 to your computer and use it in GitHub Desktop.
Example of sealed class for managing an API response
sealed class NetworkResponse<T>(
val data: T? = null,
val message: String? = null
) {
class Success<T>(data: T) : NetworkResponse<T>(data)
class Error<T>(message: String?, data: T? = null) : NetworkResponse<T>(data, message)
class Loading<T> : NetworkResponse<T>()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment