{-# LANGUAGE BlockArguments #-} module Util ( stmChanges, ) where import UnliftIO.STM stmChanges :: (Eq a) => STM a -> IO (STM a) stmChanges mkX = do x'T <- newTVarIO Nothing pure do x' <- readTVar x'T x <- mkX checkSTM (Just x /= x') writeTVar x'T (Just x) pure x