state Container
fun <T> stateContainer(initialState: T, validator: StateValidator<T> = NoOpValidator()): StateContainer<T>
Creates a simple immutable state container.
This is useful for basic state management without the complexity of a full state machine. The container ensures thread-safe updates and state validation.
Example usage:
data class CounterState(val count: Int = 0)
val container = stateContainer(CounterState())
val result = container.updateState { state ->
state.copy(count = state.count + 1)
}Content copied to clipboard
Return
A new ImmutableStateContainer instance
Parameters
T
The type of state being managed
initial State
The initial state of the container
validator
Optional validator for state validation (defaults to NoOpValidator)