Event

open class Event<out A>(source)

An event is a value which is defined in instantaneous moments at time.

In other words, from a denotational perspective it can be thought of as being equivalent to a List<Pair<Time, A>>.

Visually, you can think of a time as a graph, where the x-axis is time, and the y-axis is the value of the events:

^
| *
| * *
| * * *
| * *
|---------------------------------->

For convenience, an Event is also a kotlinx.coroutines.flow.Flow, and so it can be collected on, but it may have slightly different behavior than most flows you are used to from kotlinx.coroutines such as kotlinx.coroutines.flow.MutableSharedFlow.

To use an Event idiomatically, you should avoid using collect unless absolutely necessary for your application -- and if necessary, collect should only be used at the "edges" of your application.

Conceptually, an Event can be viewed as a Signal

Inheritors

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Functions

Link copied to clipboard
Link copied to clipboard
suspend fun collect(collector: FlowCollector<A>)
Link copied to clipboard
fun <A> Event<A>.debounced(window: Duration): Event<A>

Blocks occurrence of events until the window of time has passed, after which the latest event will be emitted.

Link copied to clipboard
fun filter(f: (A) -> Boolean): Event<A>

Applies the supplied function to each element of the Event, and produces an event that only emits if the function evaluates to true.

Link copied to clipboard
fun gate(condition: Behavior<Boolean>): Event<A>

Returns an Event that only fires if the condition does not hold at a particular time.

Link copied to clipboard
fun hold(initial: @UnsafeVariance A): Signal<A>

Method version of Signal.hold.

Link copied to clipboard
inline fun <A> Event<A>.impulse(zero: @UnsafeVariance A): Behavior<A>

Builds a dirac impulse whose value is equal to the event values when the even has fired, and whole value is equal to zero otherwise

inline fun <A, B> Event<A>.impulse(zero: B, value: B): Behavior<B>

Builds a dirac impulse whose value is equal to value whenever the event fires, and zero otherwise.

Link copied to clipboard
fun <B> map(f: SampleScope.(A) -> B): Event<B>

Applies the passed function f to each event that is emitted, producing a new transformed Event stream.

Link copied to clipboard
fun <B : Any> mapNotNull(f: (A) -> B?): Event<B>
Link copied to clipboard
fun <B> scan(initial: B, reducer: SampleScope.(B, A) -> B): Signal<B>

Method version of Signal.fold, for easier use in method chains.

Link copied to clipboard
fun <A> Event<A>.throttled(duration: Duration): Event<A>

Creates a modified Event that emits events at a frequency of at most duration.

Link copied to clipboard
fun window(size: Int): Event<List<A>>

Takes and event, and constructs a moving window of size when events occur.