TWSOutcome

sealed class TWSOutcome<out T>

A sealed class representing the outcome of an operation, typically for API calls. It encapsulates three possible states:

  • Progress: Indicates that data is being fetched from the API. If available, it contains cached data.

  • Success: Indicates that the API call was successful, and the data is up-to-date.

  • Error: Indicates that the API call failed. It provides the exception details and, if available, the last known data.

Inheritors

Types

Link copied to clipboard
data class Error<out T>(val exception: Exception, val data: T? = null) : TWSOutcome<T>

Represents an error state when the API call fails.

Link copied to clipboard
data class Progress<out T>(val data: T? = null) : TWSOutcome<T>

Represents the progress state when fetching data from the API.

Link copied to clipboard
data class Success<out T>(val data: T) : TWSOutcome<T>

Represents a successful API response.

Properties

Link copied to clipboard
abstract val data: T?

The data associated with the current state.

Functions

Link copied to clipboard
fun <A, B> TWSOutcome<A>.mapData(mapper: (A) -> B): TWSOutcome<B>

Map data of this outcome, while keeping the type.