Signal

open class Signal<out A>(val node: Node<A>)(source)

A flow can be thought of as a combination of a io.github.yafrl.behaviors.Behavior and an Event.

Like a io.github.yafrl.behaviors.Behavior, a Signal has a current value which can be sampled at any time.

Like an Event, a Signal will automatically influence derived Signals when the underlying state changes -- in other words, it is reactive.

Following our graphical analogies for Event and io.github.yafrl.behaviors.Behavior, a Signal can be thought of as a stepwise function.

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

Signals are incredibly useful for representing the state of various components in an application which need to be consumed in responsive user interfaces.

They are very similar to kotlinx.coroutines.flow.StateFlows in this sense -- only better.

Inheritors

Constructors

Link copied to clipboard
constructor(node: Node<A>)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
Link copied to clipboard
val node: Node<A>

Functions

Link copied to clipboard
inline fun <A> Signal<A>.asBehavior(): Behavior<A>

Utility to convert a Signal into a behavior whose values are interpreted as the piecewise function of the values of the Signal.

Link copied to clipboard
suspend fun collectAsync(collector: FlowCollector<A>)

Launches a handler that asynchronously listens to updates on the state.

Link copied to clipboard
fun collectSync(collector: (A) -> Unit)
Link copied to clipboard
fun <B, C> combineWith(state2: Signal<B>, op: (A, B) -> C): Signal<C>

Combine two states together into a single Signal by applying a function to the two input states.

fun <B, C, D> combineWith(state2: Signal<B>, state3: Signal<C>, op: (A, B, C) -> D): Signal<D>
fun <B, C, D, E> combineWith(state2: Signal<B>, state3: Signal<C>, state4: Signal<D>, op: (A, B, C, D) -> E): Signal<E>
fun <B, C, D, E, F> combineWith(state2: Signal<B>, state3: Signal<C>, state4: Signal<D>, state5: Signal<E>, op: (A, B, C, D, E) -> F): Signal<F>
Link copied to clipboard
fun <B> flatMap(f: SampleScope.(A) -> Signal<B>): Signal<B>
Link copied to clipboard

Construct a State<A> from a nested State<State<A>> by updating whenever either the inner or outer Signal updates.

Link copied to clipboard
fun labeled(label: String): Signal<A>
Link copied to clipboard
fun <B> map(f: SampleScope.(A) -> B): Signal<B>

Applies the passed function f to each state, producing a new transformed Signal value.

Link copied to clipboard
@JvmName(name = "plusFloat2")
operator fun Signal<Float2>.plus(other: Signal<Float2>): Signal<Float2>
@JvmName(name = "plusFloat23")
operator fun Signal<Float3>.plus(other: Signal<Float3>): Signal<Float3>
operator fun Signal<Float>.plus(other: Signal<Float>): Signal<Float>
Link copied to clipboard
fun <A> Signal<Event<A>>.switch(): Event<A>

Constructs a flattened Event from a changing Signal of events over time.

Link copied to clipboard

Constructs a behavior whose value is equal to the state's current behavior's value at all times.

Link copied to clipboard
fun <B> switchMap(f: SampleScope.(A) -> Event<B>): Event<B>
Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
fun updated(): Event<A>

Get the Event with just the updates associated with a Signal.