Package rsp.state

Interface FunctionConsumer<S>

  • Type Parameters:
    S - the type of the state snapshot, an immutable class
    All Known Subinterfaces:
    UseState<S>
    All Known Implementing Classes:
    MutableState, ReadOnly

    public interface FunctionConsumer<S>
    Represents a write state snapshot operation using the result of a function which transforms the current state to a new state. The function execution and write may be performed with synchronization, making the state update atomic.
    • Method Detail

      • accept

        void accept​(Function<S,​S> function)
        Writes the new state with the result of the function.
        Parameters:
        function - the state transformation
      • acceptOptional

        void acceptOptional​(Function<S,​Optional<S>> function)
        Writes the new state with the result of the function if the result is not empty.
        Parameters:
        function - the state transformation