rainbox-0.10.0.0: Two-dimensional box pretty printing, with colors

Safe HaskellSafe-Inferred
LanguageHaskell2010

Rainbox.Array2d

Contents

Description

Helpers for two-dimensional arrays.

Synopsis

Tables

data Table lCol lRow col row a Source

A Table is a two-dimensional array with two associated one-dimensional arrays: an array of labels for each column, and an array of labels for each row.

Instances

(Ix col, Ix row) => Functor (Table lCol lRow col row) 
(Eq lCol, Eq lRow, Eq a, Ix col, Ix row) => Eq (Table lCol lRow col row a) 
(Show lCol, Show lRow, Show col, Show row, Show a, Ix col, Ix row) => Show (Table lCol lRow col row a) 

lCols :: Table lCol lRow col row a -> Array col lCol Source

One label for each column

lRows :: Table lCol lRow col row a -> Array row lRow Source

One label for each row

cells :: Table lCol lRow col row a -> Array (col, row) a Source

Two-dimensional array of cells

table Source

Arguments

:: (Ix col, Ix row) 
=> (col -> [(row, a)] -> lCol)

Function to generate the column labels. It is applied to the column index and the full contents of the column.

-> (row -> [(col, a)] -> lRow)

Function to generate the row labels. It is applied to the row index and the full contents of the row.

-> Array (col, row) a

Cells of the table

-> Table lCol lRow col row a 

Make a new Table.

labelCols Source

Arguments

:: (Ix col, Ix row) 
=> (col -> [(row, a)] -> lCol)

Function to generate the column labels. It is applied to the column index and the full contents of the column.

-> Array (col, row) a 
-> Array col lCol 

Given a two-dimensional array and a function that generates labels, return an array of column labels.

labelRows Source

Arguments

:: (Ix col, Ix row) 
=> (row -> [(col, a)] -> lRow)

Function to generate the row labels. It is applied to the row index and the full contents of the row.

-> Array (col, row) a 
-> Array row lRow 

Given a two-dimensional array and a function that generates labels, return an array of row labels.

mapTable Source

Arguments

:: (Ix col, Ix row) 
=> (lCol -> lRow -> col -> row -> a -> b)

Function is passed the label for the column, the label for the row, the column index, the row index, and the contents of the cell. It returns a new cell.

-> Table lCol lRow col row a 
-> Table lCol lRow col row b 

Transform the cells of the table. Similar to the Functor instance, but the mapping function has access to the label and index of each cell in the Table.

mapColLabels Source

Arguments

:: (Ix col, Ix row) 
=> (lCol -> col -> [(lRow, row, a)] -> lCol')

The function is passed the column label, column index, and the full contents of the column.

-> Table lCol lRow col row a 
-> Table lCol' lRow col row a 

Transform the column labels.

mapRowLabels Source

Arguments

:: (Ix col, Ix row) 
=> (lRow -> row -> [(lCol, col, a)] -> lRow')

The function is passed the row label, the row index, and the full contents of the row.

-> Table lCol lRow col row a 
-> Table lCol lRow' col row a 

Transform the row labels.

Two-dimensional arrays

cols :: (Ix col, Ix row) => Array (col, row) a -> [[a]] Source

Given a two-dimensional array, return a list of columns in order.

rows :: (Ix col, Ix row) => Array (col, row) a -> [[a]] Source

Given a two-dimensional array, return a list of rows in order.

arrayByRows Source

Arguments

:: a

Append this empty value to rows that are too short.

-> [[a]]

One list per row

-> Array (Int, Int) a 

Generate a two-dimensional array from a list of rows. Every row's length will be equal to the length of the first row; any rows after the first row that are shorter than the first row will have extra columns appended to the end. Therefore, the resulting Array will have no undefined values.

arrayByCols Source

Arguments

:: a

Append this value to columns that are too short.

-> [[a]]

One list per column; the head of each list is the top of the column.

-> Array (Int, Int) a 

Generate a two-dimensional array from a list of columns. Every column will be the same height as the first column; subsequent colums will be padded or truncated on the bottom, as needed. Therefore the resulting Array will have no undefined elements.