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