{-# LANGUAGE ViewPatterns, OverloadedStrings, FlexibleContexts #-} module Utils ( showEntity , apply, apply' , entities ) where import Data.Text (Text) import qualified Data.Text as Text import Data.PQueue.Prio.Max (MaxPQueue) import qualified Data.PQueue.Prio.Max as MaxPQueue import Data.Monoid (Monoid(..), (<>)) import Control.Monad.State.Class import Control.Monad.Writer.Class import Data.Set (Set) import qualified Data.Set as Set import Types showEntity :: Entity -> Text showEntity (Entity name number) | (Just (show -> n)) <- number = name <> " № " <> Text.pack n | otherwise = name apply' :: (MonadState Sequence m, MonadWriter History m) => Alteration -> m () apply' alteration = do (newSt, hist) <- apply alteration <$> get tell hist put newSt apply :: Alteration -> Sequence -> (Sequence, History) apply alteration seq = undefined entities :: MonadState Sequence m => m (Set Entity) entities = Set.fromList . MaxPQueue.keys <$> get