Copyright | (c) Guru Devanla 2018 |
---|---|
License | MIT |
Maintainer | grdvnl@gmail.com |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
This module provides an easy way to explore input files that may have numerous columns by helping create a Record types by guessing the types. That information can be used as is or persisted to a file so that other customizations can be performed.
- makeCsvRecord :: String -> FilePath -> String -> DecodeOptions -> DecsQ
- commaOptions :: DecodeOptions
- tabOptions :: DecodeOptions
- makeInstance :: String -> DecsQ
- loadData :: FromNamedRecord a => FilePath -> IO (Vector a)
Creating Record types
:: String | Name to use for the Record type being created |
-> FilePath | File path of input file |
-> String | Prefix to be used to field names. Recommended to use "_" to work well with Lens |
-> DecodeOptions |
|
-> DecsQ |
Makes the Record that reflects the types inferred from the input file.
commaOptions :: DecodeOptions Source #
Provides a default DecodeOptions
for comma separated input files
tabOptions :: DecodeOptions Source #
Provides a default DecodeOptions
for tab separated input files
Convinience method that creates the default instances required by Cassava. The generated methods assumed fields are prefixed with "_".
For example, if the column header in the input file have upper case or mixed case the names will not directly match with field names in the record. In that case explicity instances have to be provided manually and the field modifiers provided accordingly.
For example, if the columns in the input file have all headers listed in upper case, since the field names are all lower case, the defaultFieldNameOptions function would look like this
defaultFieldNameOptions :: Options defaultFieldNameOptions = defaultOptions { fieldLabelModifier = rmUnderscore } where rmUnderscore ('_':str) = DT.unpack . DT.toUpper . DT.pack $ str rmUnderscore str = str
Note the DT.toUpper call to convert the field names to upper case before comparing to
NamedRecords