Resource

sealed class Resource<T>

A sealed class representing different states of a resource, typically used for data fetching operations.

The Resource class has three subclasses:

  • Loading: Indicates that the data is currently being loaded.

  • Success: Indicates that the data has been successfully loaded.

  • Error: Indicates that an error occurred during data loading, with an associated error message.

Parameters

T

The type of data held by the resource.

Inheritors

Types

Link copied to clipboard
class Error<T>(message: String, data: T? = null) : Resource<T>

Represents the error state of a resource.

Link copied to clipboard
class Loading<T>(data: T? = null) : Resource<T>

Represents the loading state of a resource.

Link copied to clipboard
class Success<T>(data: T) : Resource<T>

Represents the success state of a resource.

Properties

Link copied to clipboard
val data: T? = null

The data associated with the resource, if available.

Link copied to clipboard
val message: String? = null

A descriptive message associated with the resource, usually for error states.