-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Pretty Print containers in a tabular format -- -- Please see README.md @package pptable @version 0.1.0.1 -- | Module implements the default methods for Tabilize module Text.PrettyPrint.Tabilize -- | Specialized class that provides default methods methods to print List, -- Map or Vector values as a pretty table class (Data a) => Tabilize a where listToBox a = case a of { [] -> [[nullBox]] x : xs -> gprintTable (from x) : listToBox xs } mapToBox m = elems (mapWithKey (\ k v -> text (show k) : gprintTable (from v)) m) vectorToBox v = toList $ fmap (\ x -> (gprintTable (from x))) v printMap m = do { let r = head . elems $ m; let header = constrFields . toConstr $ r; let header_box = "Key" : map (text) header; printBox $ alignBox $ header_box : mapToBox m } printList m = do { let r = head $ m; let header = constrFields . toConstr $ r; let header_box = map (text) header; printBox $ alignBox $ header_box : listToBox m } printVector m = do { let r = m ! 0; let header = constrFields . toConstr $ r; let header_box = map (text) header; printBox $ alignBox $ header_box : vectorToBox m } -- | Return a list of values wrapped in a Box. Each entry in input is -- assumed to be a list of records keyed by any data type. The first -- entry in the list of values will be used to infer the names of fields listToBox :: Tabilize a => [a] -> [[Box]] -- | Return a list of values wrapped in Box. Each entry in input is assumed -- to be a list of records keyed by any data type. The first entry in the -- list of values will be used to infer the names of fields mapToBox :: (Tabilize a, Show b) => Map b a -> [[Box]] -- | Return a list of values wrapped in Box. Each entry in input is assumed -- to be a list of records keyed by any data type. The first entry in the -- list of values will be used to infer the names of fields vectorToBox :: Tabilize a => Vector a -> [[Box]] -- | Return a list of values wrapped in a Box. Each entry in input is -- assumed to be a list of records keyed by any data type. The first -- entry in the list of values will be used to infer the names of fields listToBox :: (Tabilize a, Generic a, GTabilize (Rep a)) => [a] -> [[Box]] -- | Return a list of values wrapped in Box. Each entry in input is assumed -- to be a list of records keyed by any data type. The first entry in the -- list of values will be used to infer the names of fields mapToBox :: (Tabilize a, Generic a, GTabilize (Rep a), Show b) => Map b a -> [[Box]] -- | Return a list of values wrapped in Box. Each entry in input is assumed -- to be a list of records keyed by any data type. The first entry in the -- list of values will be used to infer the names of fields vectorToBox :: (Tabilize a, Generic a, GTabilize (Rep a)) => Vector a -> [[Box]] -- |
-- import qualified Data.Map as M
-- -- declare a Map
-- data Portfolio = M.Map String Stock
-- Add the Stock values we create
-- let p = M.fromList [("YHOO", yahoo), ("GOOG", google), ("AMZN" amazon)]
--
-- printMap p
--
-- Key ticker price marketCap
-- "amzn" "AMZN" 799.161717 3.7886e11
-- "goog" "GOOG" 774.210101 5.3209e11
-- "yhoo" "YHOO" 42.2910101 4.0e10
--
printMap :: (Tabilize a, Show b) => Map b a -> IO ()
-- | -- -- List of records -- let tickers = [yahoo, google, amazon] -- -- printList tickers -- -- ticker price marketCap -- "YHOO" 42.2910101 4.0e10 -- "GOOG" 774.210101 5.3209e11 -- "AMZN" 799.161717 3.7886e11 --printList :: Tabilize a => [a] -> IO () -- |
-- import qualified Data.Vector as V -- -- Vector of records -- let tickers = V.fromList [yahoo, google, amazon] -- -- printVector tickers -- -- ticker price marketCap -- "YHOO" 42.2910101 4.0e10 -- "GOOG" 774.210101 5.3209e11 -- "AMZN" 799.161717 3.7886e11 --printVector :: Tabilize a => Vector a -> IO () -- |
-- -- List of records -- let tickers = [yahoo, google, amazon] -- -- printList tickers -- -- ticker price marketCap -- "YHOO" 42.2910101 4.0e10 -- "GOOG" 774.210101 5.3209e11 -- "AMZN" 799.161717 3.7886e11 --printList :: Tabilize a => [a] -> IO () -- |
-- import qualified Data.Map as M
-- -- declare a Map
-- data Portfolio = M.Map String Stock
-- Add the Stock values we create
-- let p = M.fromList [("YHOO", yahoo), ("GOOG", google), ("AMZN" amazon)]
--
-- printMap p
--
-- Key ticker price marketCap
-- "amzn" "AMZN" 799.161717 3.7886e11
-- "goog" "GOOG" 774.210101 5.3209e11
-- "yhoo" "YHOO" 42.2910101 4.0e10
--
printMap :: (Tabilize a, Show b) => Map b a -> IO ()
-- | -- import qualified Data.Vector as V -- -- Vector of records -- let tickers = V.fromList [yahoo, google, amazon] -- -- printVector tickers -- -- ticker price marketCap -- "YHOO" 42.2910101 4.0e10 -- "GOOG" 774.210101 5.3209e11 -- "AMZN" 799.161717 3.7886e11 --printVector :: Tabilize a => Vector a -> IO () -- | Return a list of values wrapped in a Box. Each entry in input is -- assumed to be a list of records keyed by any data type. The first -- entry in the list of values will be used to infer the names of fields listToBox :: Tabilize a => [a] -> [[Box]] -- | Return a list of values wrapped in Box. Each entry in input is assumed -- to be a list of records keyed by any data type. The first entry in the -- list of values will be used to infer the names of fields mapToBox :: (Tabilize a, Show b) => Map b a -> [[Box]] -- | Return a list of values wrapped in Box. Each entry in input is assumed -- to be a list of records keyed by any data type. The first entry in the -- list of values will be used to infer the names of fields vectorToBox :: Tabilize a => Vector a -> [[Box]] instance Text.PrettyPrint.Tabilize.GTabilize GHC.Generics.U1 instance (Text.PrettyPrint.Tabilize.GTabilize a, Text.PrettyPrint.Tabilize.GTabilize b) => Text.PrettyPrint.Tabilize.GTabilize (a GHC.Generics.:*: b) instance (Text.PrettyPrint.Tabilize.GTabilize a, Text.PrettyPrint.Tabilize.GTabilize b) => Text.PrettyPrint.Tabilize.GTabilize (a GHC.Generics.:+: b) instance Text.PrettyPrint.Tabilize.GTabilize a => Text.PrettyPrint.Tabilize.GTabilize (GHC.Generics.M1 i c a) instance (Data.Data.Data a, GHC.Show.Show a) => Text.PrettyPrint.Tabilize.GTabilize (GHC.Generics.K1 i a) -- | This module features methods that can be used to print values -- contained inside a list / a map / or a vector in a tabular format. module Text.PrettyPrint.PrettyTable -- | Specialized class that provides default methods methods to print List, -- Map or Vector values as a pretty table class (Data a) => Tabilize a where listToBox a = case a of { [] -> [[nullBox]] x : xs -> gprintTable (from x) : listToBox xs } mapToBox m = elems (mapWithKey (\ k v -> text (show k) : gprintTable (from v)) m) vectorToBox v = toList $ fmap (\ x -> (gprintTable (from x))) v printMap m = do { let r = head . elems $ m; let header = constrFields . toConstr $ r; let header_box = "Key" : map (text) header; printBox $ alignBox $ header_box : mapToBox m } printList m = do { let r = head $ m; let header = constrFields . toConstr $ r; let header_box = map (text) header; printBox $ alignBox $ header_box : listToBox m } printVector m = do { let r = m ! 0; let header = constrFields . toConstr $ r; let header_box = map (text) header; printBox $ alignBox $ header_box : vectorToBox m } -- | Return a list of values wrapped in a Box. Each entry in input is -- assumed to be a list of records keyed by any data type. The first -- entry in the list of values will be used to infer the names of fields listToBox :: Tabilize a => [a] -> [[Box]] -- | Return a list of values wrapped in Box. Each entry in input is assumed -- to be a list of records keyed by any data type. The first entry in the -- list of values will be used to infer the names of fields mapToBox :: (Tabilize a, Show b) => Map b a -> [[Box]] -- | Return a list of values wrapped in Box. Each entry in input is assumed -- to be a list of records keyed by any data type. The first entry in the -- list of values will be used to infer the names of fields vectorToBox :: Tabilize a => Vector a -> [[Box]] -- | Return a list of values wrapped in a Box. Each entry in input is -- assumed to be a list of records keyed by any data type. The first -- entry in the list of values will be used to infer the names of fields listToBox :: (Tabilize a, Generic a, GTabilize (Rep a)) => [a] -> [[Box]] -- | Return a list of values wrapped in Box. Each entry in input is assumed -- to be a list of records keyed by any data type. The first entry in the -- list of values will be used to infer the names of fields mapToBox :: (Tabilize a, Generic a, GTabilize (Rep a), Show b) => Map b a -> [[Box]] -- | Return a list of values wrapped in Box. Each entry in input is assumed -- to be a list of records keyed by any data type. The first entry in the -- list of values will be used to infer the names of fields vectorToBox :: (Tabilize a, Generic a, GTabilize (Rep a)) => Vector a -> [[Box]] -- |
-- import qualified Data.Map as M
-- -- declare a Map
-- data Portfolio = M.Map String Stock
-- Add the Stock values we create
-- let p = M.fromList [("YHOO", yahoo), ("GOOG", google), ("AMZN" amazon)]
--
-- printMap p
--
-- Key ticker price marketCap
-- "amzn" "AMZN" 799.161717 3.7886e11
-- "goog" "GOOG" 774.210101 5.3209e11
-- "yhoo" "YHOO" 42.2910101 4.0e10
--
printMap :: (Tabilize a, Show b) => Map b a -> IO ()
-- | -- -- List of records -- let tickers = [yahoo, google, amazon] -- -- printList tickers -- -- ticker price marketCap -- "YHOO" 42.2910101 4.0e10 -- "GOOG" 774.210101 5.3209e11 -- "AMZN" 799.161717 3.7886e11 --printList :: Tabilize a => [a] -> IO () -- |
-- import qualified Data.Vector as V -- -- Vector of records -- let tickers = V.fromList [yahoo, google, amazon] -- -- printVector tickers -- -- ticker price marketCap -- "YHOO" 42.2910101 4.0e10 -- "GOOG" 774.210101 5.3209e11 -- "AMZN" 799.161717 3.7886e11 --printVector :: Tabilize a => Vector a -> IO ()