rainbox-0.8.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 :: [[a]] -> Array (Int, Int) a Source

Generate a two-dimensional array from a list of rows. Each row must be of equal length; otherwise, the generated array will have undefined elements.

arrayByCols :: [[a]] -> Array (Int, Int) a Source

Generate a two-dimensional array from a list of columns. Each column must be of equal length; otherwise, the generated array will have undefined elements.