From ea2a725e9d5d758495b556631c3280de9d97fa0a Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Wed, 10 Apr 2024 14:05:08 +0200 Subject: init --- app/Util.hs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 app/Util.hs (limited to 'app/Util.hs') diff --git a/app/Util.hs b/app/Util.hs new file mode 100644 index 0000000..308ef88 --- /dev/null +++ b/app/Util.hs @@ -0,0 +1,18 @@ +{-# 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 -- cgit v1.2.3