Immutable State Container
Thread-safe implementation of StateContainer that maintains immutable state.
This implementation ensures that:
State objects remain immutable after creation
All operations are thread-safe without external synchronization
State validation is enforced on every update
Failed updates leave the current state unchanged
Parameters
The type of state being managed
Functions
Conditionally updates the state only if the current state matches the expected state.
Updates the state and returns the previous state if successful, or null if failed.
Returns the current state cast to the specified type, or null if not of that type.
Returns true if the current state is of the specified type.
Updates the state and returns the new state if successful, or null if failed.
Extension function for StateContainer to perform atomic updates.
Updates the state using the provided updater function.
Transforms the state using a suspending function while maintaining thread safety.
Validates the given state using the container's validator.