pptable-0.3.0.0: Pretty Print containers in a tabular format

Safe HaskellNone
LanguageHaskell2010

Text.PrettyPrint.Tabulate

Description

Module implements the default methods for Tabulate All examples listed in the document need the following language pragmas and following modules imported

{#- LANGUAGE MultiParamTypeClasses}
{#- LANGUAGE DeriveGeneric}
{#- LANGUAGE DeriveDataTypeable}

import qualified GHC.Generics as G
import Data.Data
Synopsis

Documentation

class Tabulate a flag | a -> flag #

Class instance that needs to be instantiated for each record that needs to be printed using printTable

data Stock = Stock {price:: Double, name:: String} derive (Show, G.Generic, Data)
instance Tabulate S ExpandWhenNested

If S is embedded inside another Record type and should be displayed in regular Record Syntax, then

instance Tabulate S DoNotExpandWhenNested
Instances
flag ~ DoNotExpandWhenNested => Tabulate a flag # 
Instance details

Defined in Text.PrettyPrint.Tabulate

class Boxable b where #

Methods

printTable :: (Generic a, GRecordMeta (Rep a)) => b a -> IO () #

Used to print a container of Records in a tabular format.

data Stock = Stock {price:: Double, ticker:: String} deriving (Show, Data, G.Generic)
instance Tabulate Stock DoNotExpandWhenNested
-- this can be a Vector or Map
let s =  [Stock 10.0 "yahoo", Stock 12.0 "goog", Stock 10.0 "amz"]
T.printTable s

Nested records can also be printed in tabular format

data FxCode = USD | EUR deriving (Show, Data, G.Generic)
instance CellValueFormatter FxCode

data Price = Price {px:: Double, fxCode:: FxCode} deriving (Show, Data, G.Generic)
instance Tabulate Price ExpandWhenNested
-- since Price will be nested, it also needs an instance of
-- CellValueFormatter
instance CellValueFormatter Price

data Stock = Stock {ticker:: String, price:: Price} deriving (Show, Data, G.Generic)
instance Tabulate Stock DoNotExpandWhenNested

-- this can be a Vector or Map
let s =  [Stock "yahoo" (Price 10.0 USD), Stock "ikea" (Price 11.0 EUR)]
printTable s

renderTable :: (Generic a, GRecordMeta (Rep a)) => b a -> Box #

Similar to printTable but rather than return IO (), returns a Box object that can be printed later on, using printBox

printTableWithFlds :: [DisplayFld t] -> b t -> IO () #

Used for printing selected fields from Record types This is useful when Records have a large number of fields and only few fields need to be introspected at any time.

Using the example provided under printTables,

printTableWithFlds [DFld (px . price), DFld ticker] s

renderTableWithFlds :: [DisplayFld t] -> b t -> Box #

Same as printTableWithFlds but returns a Box object, rather than returning an `IO ()`.

Instances
Boxable [] #

Instance methods to render or print a list of records in a tabular format.

Instance details

Defined in Text.PrettyPrint.Tabulate

Methods

printTable :: (Generic a, GRecordMeta (Rep a)) => [a] -> IO () #

renderTable :: (Generic a, GRecordMeta (Rep a)) => [a] -> Box #

printTableWithFlds :: [DisplayFld t] -> [t] -> IO () #

renderTableWithFlds :: [DisplayFld t] -> [t] -> Box #

Boxable Vector # 
Instance details

Defined in Text.PrettyPrint.Tabulate

Methods

printTable :: (Generic a, GRecordMeta (Rep a)) => Vector a -> IO () #

renderTable :: (Generic a, GRecordMeta (Rep a)) => Vector a -> Box #

printTableWithFlds :: [DisplayFld t] -> Vector t -> IO () #

renderTableWithFlds :: [DisplayFld t] -> Vector t -> Box #

CellValueFormatter k => Boxable (Map k) # 
Instance details

Defined in Text.PrettyPrint.Tabulate

Methods

printTable :: (Generic a, GRecordMeta (Rep a)) => Map k a -> IO () #

renderTable :: (Generic a, GRecordMeta (Rep a)) => Map k a -> Box #

printTableWithFlds :: [DisplayFld t] -> Map k t -> IO () #

renderTableWithFlds :: [DisplayFld t] -> Map k t -> Box #

class CellValueFormatter a #

Class that implements formatting using printf. Default instances for String, Char, Int, Integer, Double and Float are provided. For types that are not an instance of this class show is used.

Instances
CellValueFormatter Bool # 
Instance details

Defined in Text.PrettyPrint.Tabulate

Methods

ppFormatter :: Bool -> String

ppFormatterWithStyle :: TablizeValueFormat -> Bool -> String

CellValueFormatter Double # 
Instance details

Defined in Text.PrettyPrint.Tabulate

Methods

ppFormatter :: Double -> String

ppFormatterWithStyle :: TablizeValueFormat -> Double -> String

CellValueFormatter Float # 
Instance details

Defined in Text.PrettyPrint.Tabulate

Methods

ppFormatter :: Float -> String

ppFormatterWithStyle :: TablizeValueFormat -> Float -> String

CellValueFormatter Int # 
Instance details

Defined in Text.PrettyPrint.Tabulate

Methods

ppFormatter :: Int -> String

ppFormatterWithStyle :: TablizeValueFormat -> Int -> String

CellValueFormatter Integer # 
Instance details

Defined in Text.PrettyPrint.Tabulate

Methods

ppFormatter :: Integer -> String

ppFormatterWithStyle :: TablizeValueFormat -> Integer -> String

CellValueFormatter String # 
Instance details

Defined in Text.PrettyPrint.Tabulate

Methods

ppFormatter :: String -> String

ppFormatterWithStyle :: TablizeValueFormat -> String -> String

(Show a, CellValueFormatter a) => CellValueFormatter (Maybe a) # 
Instance details

Defined in Text.PrettyPrint.Tabulate

Methods

ppFormatter :: Maybe a -> String

ppFormatterWithStyle :: TablizeValueFormat -> Maybe a -> String

data ExpandWhenNested #

Use this flag to expand a Record Type as a table when nested inside another record.

data DoNotExpandWhenNested #

Use this flag to not expand a Record type as a table when nested inside another record. The Show instance of the nested record is used by default without expanding. This means that the fields of the nested record are not displayed as separate headers.

data DisplayFld a #

Constructors

CellValueFormatter s => DFld (a -> s)