fold
Construct a Signal by suppling an initial value, a set of events driving the updates of the Signal, together with a reducer describing how new events update the existing state.
Example:
enum class CounterEvent {
Increment,
Decrement;
}
val events: Event<CounterEvent> = ...
val counter: State<Int> = State.fold(0, incrementEvents) { state, event ->
when (event) {
is CounterEvent.Increment -> state + 1
is CounterEvent.Decrement -> state - 1
}
}
Content copied to clipboard