cassava-records- Auto-generation of records data type.

Copyright(c) Guru Devanla 2018
Safe HaskellNone




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.


Creating Record types


makeCsvRecord Source #


:: 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

DecodeOptions as required by Cassava to read the input file

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

makeInstance Source #


:: String

name of record for which the instance needs to be created

-> DecsQ 

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 }
    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


loadData Source #


:: FromNamedRecord a 
=> FilePath

Path of the file to be loaded

-> IO (Vector a)

a will be of a Record type

Helper function to load the data from the the provided file path