Result

sealed class Result<out T>

Result of a type T.

It is either of type Success or Error.

Types

Error
Link copied to clipboard
data class Error(throwable: Throwable) : Result<Nothing>

Indicates an error state.

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

Indicates a success state.

Functions

mapData
Link copied to clipboard
fun <S> mapData(dataMapper: (T) -> S): Result<S>

Maps the type T to type S.

mapError
Link copied to clipboard
fun mapError(mapper: (Throwable) -> Exception): Result<T>
mapToUnit
Link copied to clipboard
fun mapToUnit(): Result<Unit>

Maps the type T to Unit.

onError
Link copied to clipboard
fun onError(callback: (Throwable) -> Unit): Result<T>

Convenience method to listen for Error.

onSuccess
Link copied to clipboard
fun onSuccess(callback: (T) -> Unit): Result<T>

Convenience method to listen for Success.

Properties

dataOrNull
Link copied to clipboard
val dataOrNull: T?

Convenience property to directly get the Success.data of T if this Result is a Success or null otherwise.

throwableOrNull
Link copied to clipboard
val throwableOrNull: Throwable?

Convenience property to directly get the Error.throwable if this Result is an Error or null otherwise

Inheritors

Result
Link copied to clipboard
Result
Link copied to clipboard