{-# LANGUAGE Safe #-}

-- | Lifted reexports from 'Data.IORef' module.

module Universum.Lifted.IORef
       ( IORef
       , atomicModifyIORef
       , atomicModifyIORef'
       , atomicWriteIORef
       , modifyIORef
       , modifyIORef'
       , newIORef
       , readIORef
       , writeIORef
       ) where

import Control.Monad.Trans (MonadIO, liftIO)
import Data.Function (($), (.))
import Data.IORef (IORef)

import qualified Data.IORef as Ref (atomicModifyIORef, atomicModifyIORef', atomicWriteIORef,
                                    modifyIORef, modifyIORef', newIORef, readIORef, writeIORef)

-- | Lifted version of 'Ref.newIORef'.
newIORef :: MonadIO m => a -> m (IORef a)
newIORef :: a -> m (IORef a)
newIORef = IO (IORef a) -> m (IORef a)
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (IORef a) -> m (IORef a))
-> (a -> IO (IORef a)) -> a -> m (IORef a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> IO (IORef a)
forall a. a -> IO (IORef a)
Ref.newIORef
{-# INLINE newIORef #-}

-- | Lifted version of 'Ref.readIORef'.
readIORef :: MonadIO m => IORef a -> m a
readIORef :: IORef a -> m a
readIORef = IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO a -> m a) -> (IORef a -> IO a) -> IORef a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. IORef a -> IO a
forall a. IORef a -> IO a
Ref.readIORef
{-# INLINE readIORef #-}

-- | Lifted version of 'Ref.writeIORef'.
writeIORef :: MonadIO m => IORef a -> a -> m ()
writeIORef :: IORef a -> a -> m ()
writeIORef IORef a
ref a
what = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ IORef a -> a -> IO ()
forall a. IORef a -> a -> IO ()
Ref.writeIORef IORef a
ref a
what
{-# INLINE writeIORef #-}

-- | Lifted version of 'Ref.modifyIORef'.
modifyIORef :: MonadIO m => IORef a -> (a -> a) -> m ()
modifyIORef :: IORef a -> (a -> a) -> m ()
modifyIORef IORef a
ref a -> a
how = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ IORef a -> (a -> a) -> IO ()
forall a. IORef a -> (a -> a) -> IO ()
Ref.modifyIORef IORef a
ref a -> a
how
{-# INLINE modifyIORef #-}

-- | Lifted version of 'Ref.modifyIORef''.
modifyIORef' :: MonadIO m => IORef a -> (a -> a) -> m ()
modifyIORef' :: IORef a -> (a -> a) -> m ()
modifyIORef' IORef a
ref a -> a
how = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ IORef a -> (a -> a) -> IO ()
forall a. IORef a -> (a -> a) -> IO ()
Ref.modifyIORef' IORef a
ref a -> a
how
{-# INLINE modifyIORef' #-}

-- | Lifted version of 'Ref.atomicModifyIORef'.
atomicModifyIORef :: MonadIO m => IORef a -> (a -> (a, b)) -> m b
atomicModifyIORef :: IORef a -> (a -> (a, b)) -> m b
atomicModifyIORef IORef a
ref a -> (a, b)
how = IO b -> m b
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO b -> m b) -> IO b -> m b
forall a b. (a -> b) -> a -> b
$ IORef a -> (a -> (a, b)) -> IO b
forall a b. IORef a -> (a -> (a, b)) -> IO b
Ref.atomicModifyIORef IORef a
ref a -> (a, b)
how
{-# INLINE atomicModifyIORef #-}

-- | Lifted version of 'Ref.atomicModifyIORef''.
atomicModifyIORef' :: MonadIO m => IORef a -> (a -> (a, b)) -> m b
atomicModifyIORef' :: IORef a -> (a -> (a, b)) -> m b
atomicModifyIORef' IORef a
ref a -> (a, b)
how = IO b -> m b
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO b -> m b) -> IO b -> m b
forall a b. (a -> b) -> a -> b
$ IORef a -> (a -> (a, b)) -> IO b
forall a b. IORef a -> (a -> (a, b)) -> IO b
Ref.atomicModifyIORef' IORef a
ref a -> (a, b)
how
{-# INLINE atomicModifyIORef' #-}

-- | Lifted version of 'Ref.atomicWriteIORef'.
atomicWriteIORef :: MonadIO m => IORef a -> a -> m ()
atomicWriteIORef :: IORef a -> a -> m ()
atomicWriteIORef IORef a
ref a
what = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ IORef a -> a -> IO ()
forall a. IORef a -> a -> IO ()
Ref.atomicWriteIORef IORef a
ref a
what
{-# INLINE atomicWriteIORef #-}