@hackage atomic-modify-general0.1.0.0

Generalizations of atomicModifyIORef

base provides

atomicModifyIORef :: IORef a -> (a -> (a, b)) -> IO b
atomicModifyIORef2 :: IORef a -> (a -> (a, b)) -> IO (a, (a, b))

to modify the value in an IORef and return a result (and, in the case of atomicModifyIORef2, also return the old value).

In Data.IORef.AtomicModify, we generalize this from pairs to arbitrary types for which the user can provide a function to extract the new value to store in the IORef.

In Data.IORef.AtomicModify.Generic, we offer a faster but more restricted version taking advantage of the fact that the primop used to implement atomicModifyIORef2 actually works for somewhat more general record types than atomicModifyIORef2 accepts.