Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- class ToNamedRecord a
- class DefaultOrdered a
- type FromCsvField = FromField
- type ToCsvField = ToField
- parseCsvField :: FromCsvField a => Field -> Parser a
- toCsvField :: ToCsvField a => a -> Field
Documentation
class ToNamedRecord a #
A type that can be converted to a single CSV record.
An example type and instance:
data Person = Person { name :: !Text, age :: !Int } instance ToNamedRecord Person where toNamedRecord (Person name age) = namedRecord [ "name" .= name, "age" .= age]
Instances
(Eq a, ToField a, ToField b, Hashable a) => ToNamedRecord (HashMap a b) | |
Defined in Data.Csv.Conversion toNamedRecord :: HashMap a b -> NamedRecord # | |
(ToField a, ToField b, Ord a) => ToNamedRecord (Map a b) | |
Defined in Data.Csv.Conversion toNamedRecord :: Map a b -> NamedRecord # |
class DefaultOrdered a #
A type that has a default field order when converted to CSV. This
class lets you specify how to get the headers to use for a record
type that's an instance of ToNamedRecord
.
To derive an instance, the type is required to only have one constructor and that constructor must have named fields (also known as selectors) for all fields.
Right: data Foo = Foo { foo :: !Int }
Wrong: data Bar = Bar Int
If you try to derive an instance using GHC generics and your type doesn't have named fields, you will get an error along the lines of:
<interactive>:9:10: No instance for (DefaultOrdered (M1 S NoSelector (K1 R Char) ())) arising from a use of ‘Data.Csv.Conversion.$gdmheader’ In the expression: Data.Csv.Conversion.$gdmheader In an equation for ‘header’: header = Data.Csv.Conversion.$gdmheader In the instance declaration for ‘DefaultOrdered Foo’
type FromCsvField = FromField Source #
type ToCsvField = ToField Source #
parseCsvField :: FromCsvField a => Field -> Parser a Source #
toCsvField :: ToCsvField a => a -> Field Source #