prolude-0.0.0.8: ITProTV's custom prelude
Safe HaskellNone
LanguageHaskell2010

Prolude.Csv

Synopsis

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

Instances details
(Eq a, ToField a, ToField b, Hashable a) => ToNamedRecord (HashMap a b) 
Instance details

Defined in Data.Csv.Conversion

(ToField a, ToField b, Ord a) => ToNamedRecord (Map a b) 
Instance details

Defined in Data.Csv.Conversion

Methods

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’