Source

iotransaction / src / IoTransactionTest.hs

Full commit
import IoTransaction
import System.IO
import System.FilePath.Posix

updateFile :: FilePath -> FilePath -> UndoableIO ()

updateFile path sourcePath = do -- get current contents
                                oldContents <- doAction $ readFile path

                                -- get new contents from external data source
                                newContents <- doAction $ readFile sourcePath

                                -- write new contents
                                doAction $ writeFile path newContents
                                
                                -- add an undo action that rewrites the old contents
                                addUndoer $ writeFile path oldContents

scenario1 :: IO ()
scenario1 = do writeFile "file1" "old contents 1"
               writeFile "file2" "old contents 2"
               writeFile "source1" "hello"
               writeFile "source2" "goodbye"
               
               exec $ do updateFile "file1" "source1"
                         updateFile "file2" "doesntExist"

main = scenario1