Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Rainbox.Array2d
Contents
Description
Helpers for two-dimensional arrays.
- data Table lCol lRow col row a
- lCols :: Table lCol lRow col row a -> Array col lCol
- lRows :: Table lCol lRow col row a -> Array row lRow
- cells :: Table lCol lRow col row a -> Array (col, row) a
- table :: (Ix col, Ix row) => (col -> [(row, a)] -> lCol) -> (row -> [(col, a)] -> lRow) -> Array (col, row) a -> Table lCol lRow col row a
- labelCols :: (Ix col, Ix row) => (col -> [(row, a)] -> lCol) -> Array (col, row) a -> Array col lCol
- labelRows :: (Ix col, Ix row) => (row -> [(col, a)] -> lRow) -> Array (col, row) a -> Array row lRow
- mapTable :: (Ix col, Ix row) => (lCol -> lRow -> col -> row -> a -> b) -> Table lCol lRow col row a -> Table lCol lRow col row b
- mapColLabels :: (Ix col, Ix row) => (lCol -> col -> [(lRow, row, a)] -> lCol') -> Table lCol lRow col row a -> Table lCol' lRow col row a
- mapRowLabels :: (Ix col, Ix row) => (lRow -> row -> [(lCol, col, a)] -> lRow') -> Table lCol lRow col row a -> Table lCol lRow' col row a
- cols :: (Ix col, Ix row) => Array (col, row) a -> [[a]]
- rows :: (Ix col, Ix row) => Array (col, row) a -> [[a]]
- arrayByRows :: a -> [[a]] -> Array (Int, Int) a
- arrayByCols :: a -> [[a]] -> Array (Int, Int) a
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.
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.
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.
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.
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
.
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.
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.
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.
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.