modify package:relude

Monadic state transformer. Maps an old state to a new state inside a state monad. The old state is thrown away.
Main> :t modify ((+1) :: Int -> Int)
modify (...) :: (MonadState Int a) => a ()
This says that modify (+1) acts over any Monad that is a member of the MonadState class, with an Int state.
Strict version of modifyTVar.
Lifted version of modifyIORef.
>>> ref <- newIORef 42

>>> modifyIORef ref (\a -> a + 6)

>>> readIORef ref
48
Lifted version of modifyIORef'.
>>> ref <- newIORef 42

>>> modifyIORef' ref (\a -> a + 3)

>>> readIORef ref
45
A variant of modify in which the computation is strict in the new state.
Lifted version of atomicModifyIORef.
>>> ref <- newIORef 42

>>> atomicModifyIORef ref (\a -> (a, a + 3))
45

>>> readIORef ref
42
Lifted version of atomicModifyIORef'.
>>> ref <- newIORef 42

>>> atomicModifyIORef' ref (\a -> (a, a + 3))
45

>>> readIORef ref
42
Version of atomicModifyIORef' that discards return value. Useful when you want to update IORef but not interested in the returning result.
>>> ref <- newIORef 42

>>> atomicModifyIORef'_ ref (`div` 2)

>>> readIORef ref
21
Version of atomicModifyIORef that discards return value. Useful when you want to update IORef but not interested in the returning result.
>>> ref <- newIORef 42

>>> atomicModifyIORef_ ref (`div` 2)

>>> readIORef ref
21