module BishBosh.Text.ShowList(
showsInfoPrefix,
showsWarningPrefix,
showsErrorPrefix,
showsAssociation,
capitaliseInitial,
showsSeparator,
showsDelimitedList,
showsUnterminatedList,
showsFormattedList,
showsFormattedList',
showsAssociationList,
showsAssociationList',
splitOn
) where
import qualified Data.Char
import qualified Data.List
showsInfoPrefix :: ShowS
showsInfoPrefix = showString "INFO:\t"
showsWarningPrefix :: ShowS
showsWarningPrefix = showString "WARNING:\t"
showsErrorPrefix :: ShowS
showsErrorPrefix = showString "ERROR:\t"
showsAssociation :: ShowS
showsAssociation = showString " = "
capitaliseInitial :: ShowS
capitaliseInitial (c : cs) = Data.Char.toUpper c : cs
capitaliseInitial _ = []
showsSeparator :: ShowS
showsSeparator = showString ", "
showsDelimitedList
:: ShowS
-> ShowS
-> ShowS
-> [ShowS]
-> ShowS
showsDelimitedList separator lDelimiter rDelimiter = foldr (.) rDelimiter . (lDelimiter :) . Data.List.intersperse separator
showsUnterminatedList :: [ShowS] -> ShowS
showsUnterminatedList = showsDelimitedList showsSeparator id id
showsFormattedList
:: ShowS
-> (a -> ShowS)
-> [a]
-> ShowS
showsFormattedList separator f = showsDelimitedList separator (showChar '[') (showChar ']') . map f
showsFormattedList'
:: (a -> ShowS)
-> [a]
-> ShowS
showsFormattedList' = showsFormattedList showsSeparator
showsAssociationList
:: ShowS
-> [(String, ShowS)]
-> ShowS
showsAssociationList separator = showsDelimitedList separator (showChar '{') (showChar '}') . map (
\(k, v) -> showString k . showsAssociation . v
)
showsAssociationList' :: [(String, ShowS)] -> ShowS
showsAssociationList' = showsAssociationList showsSeparator
splitOn :: (a -> Bool) -> [a] -> [[a]]
splitOn _ [] = []
splitOn predicate l = case break predicate l of
(chunk, _ : l') -> chunk : splitOn predicate l'
(chunk, []) -> [chunk]