Event

sealed interface Event<out T>(source)

Represents the reactive signal types: value, error and complete, and holds their parameter values (a value, a Throwable, nothing).

Sequence grammar: value* (error | complete)

Inheritors

Types

Link copied to clipboard
data object Complete : Event<Nothing>

Complete event.

Link copied to clipboard
class Error(val error: Throwable) : Event<Nothing>

A error event containing the error.

Link copied to clipboard
class Value<out T>(val value: T) : Event<T>

A value event containing the given value.

Functions

Link copied to clipboard
inline fun <T> Event<T>.errorOrNull(): Throwable?

Returns the encapsulated error if this Event is an Event.Error, otherwise returns null.

Link copied to clipboard
inline fun <T> Event<T>.errorOrThrow(): Throwable

Returns the encapsulated error if this Event is an Event.Error. Otherwise, throws a NoSuchElementException.

Link copied to clipboard
inline fun <T, R> Event<T>.flatMap(transform: (T) -> Event<R>): Event<R>

Returns the result of applying transform to this Event's value if this is a Event.Value. Otherwise, returns itself.

Link copied to clipboard
inline fun <T, R> Event<T>.map(transform: (T) -> R): Event<R>

When this Event is a Event.Value, return a Event.Value containing transformed value using transform. Otherwise, returns itself.

Link copied to clipboard
inline fun <T> Event<T>.valueOrDefault(defaultValue: T): T?

Returns the encapsulated value if this Event is a Event.Value, otherwise returns defaultValue.

Link copied to clipboard
inline fun <T> Event<T>.valueOrElse(defaultValue: (Throwable?) -> T): T

Returns the encapsulated value if this Event is a Event.Value, otherwise returns the result of calling defaultValue function.

Link copied to clipboard
inline fun <T> Event<T>.valueOrNull(): T?

Returns the encapsulated value if this Event is a Event.Value, otherwise returns null.

Link copied to clipboard
inline fun <T> Event<T>.valueOrThrow(): T

Returns the encapsulated value if this Event is a Event.Value. If this is Event.Error, throws the encapsulated error. Otherwise, throws a NoSuchElementException.