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

Safe HaskellSafe-Inferred

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 lColSource

One label for each column

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

One label for each row

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

Two-dimensional array of cells

tableSource

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.

labelColsSource

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.

labelRowsSource

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.

mapTableSource

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.

mapColLabelsSource

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.

mapRowLabelsSource

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) aSource

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) aSource

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.