update

fun update(transform: (S) -> S)

Replaces the state with the result of transform, which receives the current state.

The replacement is atomic: when two handlers update at once, neither update is lost. For that reason transform may run more than once and must only compute the new value.

The state must be immutable. A new state that is equal to the current one is not emitted, so a state that was changed in place (an item added to a list it already holds, for example) never reaches the UI. Build a new value instead, with copy.