{-# LANGUAGE ViewPatterns, OverloadedStrings, FlexibleContexts #-} module Utils ( showEntity , takeR ) 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 Data.Sequence (Seq, ViewR(..), (|>)) import qualified Data.Sequence as Seq import Data.CaseInsensitive ( CI ) import qualified Data.CaseInsensitive as CI import Types showEntity :: Entity -> Text showEntity (Entity name number) | (Just (show -> n)) <- number = CI.original name <> " № " <> Text.pack n | otherwise = CI.original name takeR :: Integer -> Seq a -> Seq a takeR _ (Seq.viewr -> EmptyR) = Seq.empty takeR n (Seq.viewr -> (xs :> x)) | n <= 0 = Seq.empty | otherwise = takeR (n - 1) xs |> x