modify is a StateT operation that applies a function to the current state and returns (). Its type is modify :: Monad m => (s -> s) -> StateT s m (). section 15.1.2
Use it when a computation needs to update state incrementally inside another monad, such as IO. The supplied function receives the old state and produces the replacement. section 15.1.2
Counting directories during traversal
With type App a = StateT Int IO a, modify (\x -> x + length dirs) increments the directory count before recursive traversal. Running execStateT (example "foo") 0 produces 2.
