module Table where import Data.IORef (IORef, newIORef, readIORef, modifyIORef, ) create :: a -> IO (IORef a) create = newIORef from :: IORef a -> IO a from = readIORef insert :: IORef [a] -> a -> IO () insert ref a = modifyIORef ref (a:) delete :: IORef [a] -> (a -> Bool) -> IO () delete ref p = modifyIORef ref (filter (not . p)) update :: IORef [a] -> (a -> a) -> IO () update ref f = modifyIORef ref (map f) updateWhere :: IORef [a] -> (a -> a) -> (a -> Bool) -> IO () updateWhere ref f p = modifyIORef ref (map (\x -> if p x then f x else x))