rowrecord-0.1: Build records from lists of strings, as from CSV files.




Convert lists of strings to records.



type Column = StringSource

Identifies a column.

type Row = Map Column StringSource

A row of String data.

type Table = [Row]Source

A table.

fromStrings :: [[String]] -> Result TableSource

Convert a list of String rows into a Table. Uses the first row as column names.

Parsing fields

data Result a Source

A parse result.


Success a 
Failure RowError 

data RowError Source

Possible errors from parsing a row.


class Field a whereSource

Class of field types which can be decoded from String.

The input can be Nothing to represent a missing field. The instance Field a => Field (Maybe a) models optional fields.

If your record contains custom types, you must create a Field instance for each. If you have base types but need different parsing behavior, you can use a newtype wrapper.

require :: (String -> Maybe a) -> Maybe String -> Result aSource

Implement decode for a required field.

getField :: Field a => Column -> Row -> Result aSource

Decode a field by column name.

Called from TH-generated code, but may be useful independently.

Parsing tables

class ParseRow a whereSource

Class of types which can be parsed from a Row. These types are typically single-constructor records.

Instances may be generated using Text.RowRecord.TH.


parseRow :: Row -> Result aSource

parseTable :: ParseRow a => Table -> Result [a]Source

Parse a whole table.