Safe Haskell | Safe |
---|---|
Language | Haskell2010 |
Synopsis
- class FQuery a
- class VQuery a
- class (Typeable a, FQuery a, Show a) => RFmt a
- format :: RFmt a => a -> Format a -> Box
- formatUntil :: RFmt a => Int -> a -> Format a -> Box
- fields :: FQuery a => a -> [String]
- values :: VQuery a => a -> [String]
- dfltFmt :: Format a
- simpleFmt :: (VQuery a, FQuery a) => (String -> String -> b) -> a -> [b]
- tableFmt :: TableFmt
- data Format a = Format {}
- data TableFmt = TableFmt {}
- formatTable :: RFmt a => [a] -> TableFmt -> Box
Documentation
class (Typeable a, FQuery a, Show a) => RFmt a Source #
Reduce Record to Box given a Format
Example: data List a = List { label :: String, val :: a, tail :: List a } | Nil deriving (Generic, Show) instance FQuery (List a) instance (Show a, Typeable a) => RFmt (List a) test = List "head" 3 $ List "mid" 4 $ List "tail" 5 $ Nil ghci> printBox $ format test dfltFmt label: "head" val: 3 tail: label: "mid" val: 4 tail: label: "tail" val: 5 tail: Nil
format :: RFmt a => a -> Format a -> Box Source #
Format Record a record fully expanding the data structure if it is recursive
formatUntil :: RFmt a => Int -> a -> Format a -> Box Source #
Format Record a with up to n levels of recursivity
simpleFmt :: (VQuery a, FQuery a) => (String -> String -> b) -> a -> [b] Source #
Given String representation of accessor and value return b
A Format is responsible for converting a Record into a formatted Box.
Example: dfltFmt :: Format a dfltFmt = Format { arg = text , label = \a b -> text (a <> ":") + b , finally = vcat left }
formatTable :: RFmt a => [a] -> TableFmt -> Box Source #
Format a list of RFmt instances as a table (no recursive expansion).
Example: data Employee = E { eId :: Int , name :: String , email :: String } deriving (Generic, Show) instance FQuery Employee instance RFmt Employee e1 = E 3 "John" "johnbelcherfoobar.xyz" e1 = E 3 "John" "johnbelcher
foobar.xyz" e2 = E 17 "Maria" "Mariafoobarnet.net" e3 = E 1 "Stanley" "stanleytheceo
foobar.org" e4 = E 2 "Kayla" "klabarfoo.com" e5 = E 4 "Sammy" "sammersfoobar
foo.bar" ghci> printBox $ formatTable [e1, e2, e3, e4, e5] tableFmt eId name email 3 "John" "johnbelcherfoobar.xyz" 17 "Maria" "Mariafoobar
net.net" 1 "Stanley" "stanleytheceofoobar.org" 2 "Kayla" "klabar
foo.com" 4 "Sammy" "sammersfoobar@foo.bar"