{-# LANGUAGE BangPatterns       #-}
{-# LANGUAGE ExplicitNamespaces #-}
{-# LANGUAGE GADTs              #-}
{-# LANGUAGE NamedFieldPuns     #-}
{-# LANGUAGE TypeOperators      #-}

-- | This module corresponds to `Control.Concurrent.STM.TChan` in "stm" package
--
module Control.Concurrent.Class.MonadSTM.Strict.TChan
  ( StrictTChan
  , LazyTChan
  , toLazyTChan
  , fromLazyTChan
  , castStrictTChan
  , newTChan
  , newBroadcastTChan
  , writeTChan
  , readTChan
  , tryReadTChan
  , peekTChan
  , tryPeekTChan
  , dupTChan
  , unGetTChan
  , isEmptyTChan
  , cloneTChan
  ) where


import Control.Concurrent.Class.MonadSTM.TChan qualified as Lazy
import Control.Monad.Class.MonadSTM


type LazyTChan   m = Lazy.TChan m

newtype StrictTChan m a = StrictTChan { forall (m :: * -> *) a. StrictTChan m a -> LazyTChan m a
toLazyTChan :: LazyTChan m a }

fromLazyTChan :: LazyTChan m a -> StrictTChan m a
fromLazyTChan :: forall (m :: * -> *) a. LazyTChan m a -> StrictTChan m a
fromLazyTChan = LazyTChan m a -> StrictTChan m a
forall (m :: * -> *) a. LazyTChan m a -> StrictTChan m a
StrictTChan

castStrictTChan :: LazyTChan m ~ LazyTChan n
                => StrictTChan m a -> StrictTChan n a
castStrictTChan :: forall (m :: * -> *) (n :: * -> *) a.
(LazyTChan m ~ LazyTChan n) =>
StrictTChan m a -> StrictTChan n a
castStrictTChan (StrictTChan LazyTChan m a
var) = LazyTChan n a -> StrictTChan n a
forall (m :: * -> *) a. LazyTChan m a -> StrictTChan m a
StrictTChan LazyTChan m a
LazyTChan n a
var

newTChan :: MonadSTM m => STM m (StrictTChan m a)
newTChan :: forall (m :: * -> *) a. MonadSTM m => STM m (StrictTChan m a)
newTChan = LazyTChan m a -> StrictTChan m a
forall (m :: * -> *) a. LazyTChan m a -> StrictTChan m a
StrictTChan (LazyTChan m a -> StrictTChan m a)
-> STM m (LazyTChan m a) -> STM m (StrictTChan m a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> STM m (LazyTChan m a)
forall a. STM m (TChan m a)
forall (m :: * -> *) a. MonadSTM m => STM m (TChan m a)
Lazy.newTChan

newBroadcastTChan :: MonadSTM m => STM m (StrictTChan m a)
newBroadcastTChan :: forall (m :: * -> *) a. MonadSTM m => STM m (StrictTChan m a)
newBroadcastTChan = LazyTChan m a -> StrictTChan m a
forall (m :: * -> *) a. LazyTChan m a -> StrictTChan m a
StrictTChan (LazyTChan m a -> StrictTChan m a)
-> STM m (LazyTChan m a) -> STM m (StrictTChan m a)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> STM m (LazyTChan m a)
forall a. STM m (TChan m a)
forall (m :: * -> *) a. MonadSTM m => STM m (TChan m a)
Lazy.newBroadcastTChan

writeTChan :: MonadSTM m => StrictTChan m a -> a -> STM m ()
writeTChan :: forall (m :: * -> *) a.
MonadSTM m =>
StrictTChan m a -> a -> STM m ()
writeTChan (StrictTChan LazyTChan m a
chan) !a
a = LazyTChan m a -> a -> STM m ()
forall a. TChan m a -> a -> STM m ()
forall (m :: * -> *) a. MonadSTM m => TChan m a -> a -> STM m ()
Lazy.writeTChan LazyTChan m a
chan a
a

readTChan :: MonadSTM m => StrictTChan m a -> STM m a
readTChan :: forall (m :: * -> *) a. MonadSTM m => StrictTChan m a -> STM m a
readTChan = TChan m a -> STM m a
forall a. TChan m a -> STM m a
forall (m :: * -> *) a. MonadSTM m => TChan m a -> STM m a
Lazy.readTChan (TChan m a -> STM m a)
-> (StrictTChan m a -> TChan m a) -> StrictTChan m a -> STM m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StrictTChan m a -> TChan m a
forall (m :: * -> *) a. StrictTChan m a -> LazyTChan m a
toLazyTChan

tryReadTChan :: MonadSTM m => StrictTChan m a -> STM m (Maybe a)
tryReadTChan :: forall (m :: * -> *) a.
MonadSTM m =>
StrictTChan m a -> STM m (Maybe a)
tryReadTChan = TChan m a -> STM m (Maybe a)
forall a. TChan m a -> STM m (Maybe a)
forall (m :: * -> *) a. MonadSTM m => TChan m a -> STM m (Maybe a)
Lazy.tryReadTChan (TChan m a -> STM m (Maybe a))
-> (StrictTChan m a -> TChan m a)
-> StrictTChan m a
-> STM m (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StrictTChan m a -> TChan m a
forall (m :: * -> *) a. StrictTChan m a -> LazyTChan m a
toLazyTChan

peekTChan :: MonadSTM m => StrictTChan m a -> STM m a
peekTChan :: forall (m :: * -> *) a. MonadSTM m => StrictTChan m a -> STM m a
peekTChan = TChan m a -> STM m a
forall a. TChan m a -> STM m a
forall (m :: * -> *) a. MonadSTM m => TChan m a -> STM m a
Lazy.peekTChan (TChan m a -> STM m a)
-> (StrictTChan m a -> TChan m a) -> StrictTChan m a -> STM m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StrictTChan m a -> TChan m a
forall (m :: * -> *) a. StrictTChan m a -> LazyTChan m a
toLazyTChan

tryPeekTChan :: MonadSTM m => StrictTChan m a -> STM m (Maybe a)
tryPeekTChan :: forall (m :: * -> *) a.
MonadSTM m =>
StrictTChan m a -> STM m (Maybe a)
tryPeekTChan = TChan m a -> STM m (Maybe a)
forall a. TChan m a -> STM m (Maybe a)
forall (m :: * -> *) a. MonadSTM m => TChan m a -> STM m (Maybe a)
Lazy.tryPeekTChan (TChan m a -> STM m (Maybe a))
-> (StrictTChan m a -> TChan m a)
-> StrictTChan m a
-> STM m (Maybe a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StrictTChan m a -> TChan m a
forall (m :: * -> *) a. StrictTChan m a -> LazyTChan m a
toLazyTChan

dupTChan :: MonadSTM m => StrictTChan m a -> STM m (StrictTChan m a)
dupTChan :: forall (m :: * -> *) a.
MonadSTM m =>
StrictTChan m a -> STM m (StrictTChan m a)
dupTChan = (TChan m a -> StrictTChan m a)
-> STM m (TChan m a) -> STM m (StrictTChan m a)
forall a b. (a -> b) -> STM m a -> STM m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap TChan m a -> StrictTChan m a
forall (m :: * -> *) a. LazyTChan m a -> StrictTChan m a
fromLazyTChan (STM m (TChan m a) -> STM m (StrictTChan m a))
-> (StrictTChan m a -> STM m (TChan m a))
-> StrictTChan m a
-> STM m (StrictTChan m a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TChan m a -> STM m (TChan m a)
forall a. TChan m a -> STM m (TChan m a)
forall (m :: * -> *) a.
MonadSTM m =>
TChan m a -> STM m (TChan m a)
Lazy.dupTChan (TChan m a -> STM m (TChan m a))
-> (StrictTChan m a -> TChan m a)
-> StrictTChan m a
-> STM m (TChan m a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StrictTChan m a -> TChan m a
forall (m :: * -> *) a. StrictTChan m a -> LazyTChan m a
toLazyTChan

unGetTChan :: MonadSTM m => StrictTChan m a -> a -> STM m ()
unGetTChan :: forall (m :: * -> *) a.
MonadSTM m =>
StrictTChan m a -> a -> STM m ()
unGetTChan (StrictTChan LazyTChan m a
chan) !a
a = LazyTChan m a -> a -> STM m ()
forall a. TChan m a -> a -> STM m ()
forall (m :: * -> *) a. MonadSTM m => TChan m a -> a -> STM m ()
Lazy.unGetTChan LazyTChan m a
chan a
a

isEmptyTChan :: MonadSTM m => StrictTChan m a -> STM m Bool
isEmptyTChan :: forall (m :: * -> *) a. MonadSTM m => StrictTChan m a -> STM m Bool
isEmptyTChan = TChan m a -> STM m Bool
forall a. TChan m a -> STM m Bool
forall (m :: * -> *) a. MonadSTM m => TChan m a -> STM m Bool
Lazy.isEmptyTChan (TChan m a -> STM m Bool)
-> (StrictTChan m a -> TChan m a) -> StrictTChan m a -> STM m Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StrictTChan m a -> TChan m a
forall (m :: * -> *) a. StrictTChan m a -> LazyTChan m a
toLazyTChan

cloneTChan :: MonadSTM m => StrictTChan m a -> STM m (StrictTChan m a)
cloneTChan :: forall (m :: * -> *) a.
MonadSTM m =>
StrictTChan m a -> STM m (StrictTChan m a)
cloneTChan = (TChan m a -> StrictTChan m a)
-> STM m (TChan m a) -> STM m (StrictTChan m a)
forall a b. (a -> b) -> STM m a -> STM m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap TChan m a -> StrictTChan m a
forall (m :: * -> *) a. LazyTChan m a -> StrictTChan m a
fromLazyTChan (STM m (TChan m a) -> STM m (StrictTChan m a))
-> (StrictTChan m a -> STM m (TChan m a))
-> StrictTChan m a
-> STM m (StrictTChan m a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TChan m a -> STM m (TChan m a)
forall a. TChan m a -> STM m (TChan m a)
forall (m :: * -> *) a.
MonadSTM m =>
TChan m a -> STM m (TChan m a)
Lazy.cloneTChan (TChan m a -> STM m (TChan m a))
-> (StrictTChan m a -> TChan m a)
-> StrictTChan m a
-> STM m (TChan m a)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StrictTChan m a -> TChan m a
forall (m :: * -> *) a. StrictTChan m a -> LazyTChan m a
toLazyTChan