get is a State constructor that reads the incoming state and returns it as both the action’s result and its unchanged next state. Its implementation is simply s => (s, s). section 6.6
Combined with set, map, and flatMap, get restores an imperative style without mutable data or side effects. A stateful program can read a value, bind it in a for-comprehension, and continue with the same state unless another action changes it. section 6.6
Reading state inside modify
def modify[S](f: S => S): State[S, Unit] = for s <- get _ <- set(f(s)) yield () Here get supplies the current state to f; set installs the transformed state. section 6.6
def get[S]: State[S, S] = s => (s, s)
Inspect the minimal implementation: get passes the incoming state through unchanged while returning it as the result. section 6.6
