Convert lists of strings to records.
- type Column = String
- type Row = Map Column String
- type Table = [Row]
- fromStrings :: [[String]] -> Result Table
- data Result a
- data RowError
- class Field a where
- require :: (String -> Maybe a) -> Maybe String -> Result a
- safeRead :: Read a => String -> Maybe a
- getField :: Field a => Column -> Row -> Result a
- class ParseRow a where
- parseTable :: ParseRow a => Table -> Result [a]
Tables
fromStrings :: [[String]] -> Result TableSource
Parsing fields
A parse result.
Possible errors from parsing a row.
Class of field types which can be decoded from
.
String
The input can be
to represent a missing field.
The instance Nothing
Field a => Field (Maybe a)
models optional fields.
If your record contains custom types, you must create a
instance for each. If you have base types but need different
parsing behavior, you can use a Field
newtype
wrapper.
require :: (String -> Maybe a) -> Maybe String -> Result aSource
Implement
for a required field.
decode
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 of types which can be parsed from a
.
These types are typically single-constructor records.
Row
Instances may be generated using Text.RowRecord.TH
.
parseTable :: ParseRow a => Table -> Result [a]Source
Parse a whole table.