set constructs a State action from a new state. When run, the action ignores the incoming state, replaces it with the supplied state, and returns Unit rather than a meaningful value. section 6.6
Together with get, set provides the primitive operations needed to express state changes with for-comprehensions and flatMap. Mutable data and side effects become immutable state transitions. section 6.6
Implementing modify
A general modify operation reads the current state with get, applies a function, writes the result with set, and yields (). section 6.6
def set[S](s: S): State[S, Unit] = _ => ((), s)
The implementation makes the operational behavior explicit: discard the incoming state, return Unit, and install the supplied state. section 6.6
