module Data.Niagra.Monad
(
NiagraT(..),
writeBlocks,
writeDeclarations,
niagraBlocks,
niagraDeclarations,
niagraState
)
where
import Data.Niagra.Block (Block(..),Declaration(..))
import Data.Either
import Control.Monad.Trans.Writer
import Control.Monad.IO.Class
newtype NiagraT m a = NiagraT (WriterT [Either Declaration Block] m a)
deriving (Functor, Applicative, Monad, MonadIO)
execNiagraT :: (Monad m) => NiagraT m a -> m [Either Declaration Block]
execNiagraT (NiagraT w) = execWriterT w
writeBlocks :: (Monad m) => [Block] -> NiagraT m ()
writeBlocks = NiagraT . tell . map Right
writeDeclarations :: (Monad m) => [Declaration] -> NiagraT m ()
writeDeclarations = NiagraT . tell . map Left
niagraBlocks :: (Monad m) => NiagraT m () -> m [Block]
niagraBlocks = fmap rights . execNiagraT
niagraDeclarations :: (Monad m) => NiagraT m () -> m [Declaration]
niagraDeclarations = fmap lefts . execNiagraT
niagraState :: (Monad m) => NiagraT m () -> m ([Declaration],[Block])
niagraState = fmap partitionEithers . execNiagraT