module System.Metrics.Label
(
Label
, new
, read
, set
, modify
) where
import Data.IORef (IORef, atomicModifyIORef', atomicWriteIORef, newIORef, readIORef)
import qualified Data.Text as T
import Prelude hiding (read)
newtype Label = C { unC :: IORef T.Text }
new :: IO Label
new = C `fmap` newIORef T.empty
read :: Label -> IO T.Text
read = readIORef . unC
set :: Label -> T.Text -> IO ()
set (C ref) !i = atomicWriteIORef ref i
modify :: (T.Text -> T.Text) -> Label -> IO ()
modify f (C ref) = atomicModifyIORef' ref $ \i -> (f i, ())