module Polysemy.Log.Atomic where
import Polysemy.Internal (InterpretersFor)
import Polysemy.Log.Data.DataLog (DataLog(DataLog))
import Polysemy.Log.Data.Log (Log(Log))
import Polysemy.Log.Data.LogMessage (LogMessage)
interpretDataLogAtomic' ::
∀ a r .
Member (AtomicState [a]) r =>
InterpreterFor (DataLog a) r
interpretDataLogAtomic' :: InterpreterFor (DataLog a) r
interpretDataLogAtomic' =
(forall x (rInitial :: EffectRow).
DataLog a (Sem rInitial) x -> Sem r x)
-> Sem (DataLog a : r) a -> Sem r a
forall (e :: Effect) (r :: EffectRow) a.
FirstOrder e "interpret" =>
(forall x (rInitial :: EffectRow). e (Sem rInitial) x -> Sem r x)
-> Sem (e : r) a -> Sem r a
interpret \case
DataLog msg -> ([a] -> [a]) -> Sem r ()
forall s (r :: EffectRow).
Member (AtomicState s) r =>
(s -> s) -> Sem r ()
atomicModify' (a
msg a -> [a] -> [a]
forall a. a -> [a] -> [a]
:)
{-# INLINE interpretDataLogAtomic' #-}
interpretDataLogAtomic ::
∀ a r .
Member (Embed IO) r =>
InterpretersFor [DataLog a, AtomicState [a]] r
interpretDataLogAtomic :: InterpretersFor '[DataLog a, AtomicState [a]] r
interpretDataLogAtomic Sem (Append '[DataLog a, AtomicState [a]] r) a
sem = do
TVar [a]
tv <- [a] -> Sem r (TVar [a])
forall (m :: * -> *) a. MonadIO m => a -> m (TVar a)
newTVarIO []
TVar [a] -> Sem (AtomicState [a] : r) a -> Sem r a
forall (r :: EffectRow) s a.
Member (Embed IO) r =>
TVar s -> Sem (AtomicState s : r) a -> Sem r a
runAtomicStateTVar TVar [a]
tv (Sem (DataLog a : AtomicState [a] : r) a
-> Sem (AtomicState [a] : r) a
forall a (r :: EffectRow).
Member (AtomicState [a]) r =>
InterpreterFor (DataLog a) r
interpretDataLogAtomic' Sem (DataLog a : AtomicState [a] : r) a
Sem (Append '[DataLog a, AtomicState [a]] r) a
sem)
{-# INLINE interpretDataLogAtomic #-}
interpretLogAtomic' ::
Member (AtomicState [LogMessage]) r =>
InterpreterFor Log r
interpretLogAtomic' :: InterpreterFor Log r
interpretLogAtomic' =
(forall x (rInitial :: EffectRow). Log (Sem rInitial) x -> Sem r x)
-> Sem (Log : r) a -> Sem r a
forall (e :: Effect) (r :: EffectRow) a.
FirstOrder e "interpret" =>
(forall x (rInitial :: EffectRow). e (Sem rInitial) x -> Sem r x)
-> Sem (e : r) a -> Sem r a
interpret \case
Log msg -> ([LogMessage] -> [LogMessage]) -> Sem r ()
forall s (r :: EffectRow).
Member (AtomicState s) r =>
(s -> s) -> Sem r ()
atomicModify' (LogMessage
msg LogMessage -> [LogMessage] -> [LogMessage]
forall a. a -> [a] -> [a]
:)
{-# INLINE interpretLogAtomic' #-}
interpretLogAtomic ::
Member (Embed IO) r =>
InterpretersFor [Log, AtomicState [LogMessage]] r
interpretLogAtomic :: InterpretersFor '[Log, AtomicState [LogMessage]] r
interpretLogAtomic Sem (Append '[Log, AtomicState [LogMessage]] r) a
sem = do
TVar [LogMessage]
tv <- [LogMessage] -> Sem r (TVar [LogMessage])
forall (m :: * -> *) a. MonadIO m => a -> m (TVar a)
newTVarIO []
TVar [LogMessage]
-> Sem (AtomicState [LogMessage] : r) a -> Sem r a
forall (r :: EffectRow) s a.
Member (Embed IO) r =>
TVar s -> Sem (AtomicState s : r) a -> Sem r a
runAtomicStateTVar TVar [LogMessage]
tv (Sem (Log : AtomicState [LogMessage] : r) a
-> Sem (AtomicState [LogMessage] : r) a
forall (r :: EffectRow).
Member (AtomicState [LogMessage]) r =>
InterpreterFor Log r
interpretLogAtomic' Sem (Log : AtomicState [LogMessage] : r) a
Sem (Append '[Log, AtomicState [LogMessage]] r) a
sem)
{-# INLINE interpretLogAtomic #-}