{-# LANGUAGE TypeSynonymInstances #-}
module BuildBox.Data.Log
( Log
, Line
, empty
, null
, toString
, fromString
, (<|)
, (|>)
, (><)
, firstLines
, lastLines)
where
import Data.Sequence (Seq)
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Sequence as Seq
import qualified Data.Foldable as F
import Prelude hiding (null)
type Log = Seq Line
type Line = Text
empty :: Log
empty = Seq.empty
null :: Log -> Bool
null = Seq.null
toString :: Log -> String
toString ll
= Text.unpack
$ Text.intercalate (Text.pack "\n")
$ F.toList ll
fromString :: String -> Log
fromString str
= Seq.fromList
$ Text.lines
$ Text.pack str
(<|):: Line -> Log -> Log
(<|) = (Seq.<|)
(|>) :: Log -> Line -> Log
(|>) = (Seq.|>)
(><) :: Log -> Log -> Log
(><) = (Seq.><)
firstLines :: Int -> Log -> Log
firstLines m ll
= Seq.take m ll
lastLines :: Int -> Log -> Log
lastLines m ll
= Seq.drop (Seq.length ll - m) ll