| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
SubHask.Compatibility.Cassava
Contents
- decode_ :: FromRecord a => HasHeader -> PartitionOnNewline (ByteString Char) -> Either String (BArray a)
- decode :: (NFData a, FromRecord a, ValidEq a) => HasHeader -> ByteString Char -> Either String (BArray a)
- class FromRecord a
- class ToRecord a
- class FromField a
- class ToField a
- data HasHeader :: *
Documentation
decode_ :: FromRecord a => HasHeader -> PartitionOnNewline (ByteString Char) -> Either String (BArray a) Source
This is a monoid homomorphism, which means it can be parallelized
decode :: (NFData a, FromRecord a, ValidEq a) => HasHeader -> ByteString Char -> Either String (BArray a) Source
Like the "decode" function in Data.Csv, but works in parallel
Types
class FromRecord a
A type that can be converted from a single CSV record, with the possibility of failure.
When writing an instance, use empty, mzero, or fail to make a
conversion fail, e.g. if a Record has the wrong number of
columns.
Given this example data:
John,56 Jane,55
here's an example type and instance:
data Person = Person { name :: !Text, age :: !Int }
instance FromRecord Person where
parseRecord v
| length v == 2 = Person <$>
v .! 0 <*>
v .! 1
| otherwise = mzeroInstances
class ToRecord 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 ToRecord Person where
toRecord (Person name age) = record [
toField name, toField age]Outputs data on this form:
John,56 Jane,55
Instances
| ToField a => ToRecord [a] | |
| ToField a => ToRecord (Only a) | |
| ToField a => ToRecord (Vector a) | |
| (ToField a, Unbox a) => ToRecord (Vector a) | |
| (ToField a, ToField b) => ToRecord (a, b) | |
| (ToField a, ToField b, ToField c) => ToRecord (a, b, c) | |
| (ToField a, ToField b, ToField c, ToField d) => ToRecord (a, b, c, d) | |
| (ToField a, ToField b, ToField c, ToField d, ToField e) => ToRecord (a, b, c, d, e) | |
| (ToField a, ToField b, ToField c, ToField d, ToField e, ToField f) => ToRecord (a, b, c, d, e, f) | |
| (ToField a, ToField b, ToField c, ToField d, ToField e, ToField f, ToField g) => ToRecord (a, b, c, d, e, f, g) | |
| (ToField a, ToField b, ToField c, ToField d, ToField e, ToField f, ToField g, ToField h) => ToRecord (a, b, c, d, e, f, g, h) | |
| (ToField a, ToField b, ToField c, ToField d, ToField e, ToField f, ToField g, ToField h, ToField i) => ToRecord (a, b, c, d, e, f, g, h, i) |
class FromField a
A type that can be converted from a single CSV field, with the possibility of failure.
When writing an instance, use empty, mzero, or fail to make a
conversion fail, e.g. if a Field can't be converted to the given
type.
Example type and instance:
{-# LANGUAGE OverloadedStrings #-}
data Color = Red | Green | Blue
instance FromField Color where
parseField s
| s == "R" = pure Red
| s == "G" = pure Green
| s == "B" = pure Blue
| otherwise = mzeroMinimal complete definition
Instances
| FromField Char | Assumes UTF-8 encoding. |
| FromField Double | Accepts same syntax as |
| FromField Float | Accepts same syntax as |
| FromField Int | Accepts a signed decimal number. Ignores whitespace. |
| FromField Int8 | Accepts a signed decimal number. Ignores whitespace. |
| FromField Int16 | Accepts a signed decimal number. Ignores whitespace. |
| FromField Int32 | Accepts a signed decimal number. Ignores whitespace. |
| FromField Int64 | Accepts a signed decimal number. Ignores whitespace. |
| FromField Integer | Accepts a signed decimal number. Ignores whitespace. |
| FromField Word | Accepts an unsigned decimal number. Ignores whitespace. |
| FromField Word8 | Accepts an unsigned decimal number. Ignores whitespace. |
| FromField Word16 | Accepts an unsigned decimal number. Ignores whitespace. |
| FromField Word32 | Accepts an unsigned decimal number. Ignores whitespace. |
| FromField Word64 | Accepts an unsigned decimal number. Ignores whitespace. |
| FromField () | Ignores the |
| FromField ByteString | |
| FromField ByteString | |
| FromField Text | Assumes UTF-8 encoding. Fails on invalid byte sequences. |
| FromField Text | Assumes UTF-8 encoding. Fails on invalid byte sequences. |
| FromField [Char] | Assumes UTF-8 encoding. Fails on invalid byte sequences. |
| FromField a => FromField (Maybe a) | |
| FromField a => FromField (Either Field a) |
class ToField a
A type that can be converted to a single CSV field.
Example type and instance:
{-# LANGUAGE OverloadedStrings #-}
data Color = Red | Green | Blue
instance ToField Color where
toField Red = "R"
toField Green = "G"
toField Blue = "B"Minimal complete definition
Instances
| ToField Char | Uses UTF-8 encoding. |
| ToField Double | Uses decimal notation or scientific notation, depending on the number. |
| ToField Float | Uses decimal notation or scientific notation, depending on the number. |
| ToField Int | Uses decimal encoding with optional sign. |
| ToField Int8 | Uses decimal encoding with optional sign. |
| ToField Int16 | Uses decimal encoding with optional sign. |
| ToField Int32 | Uses decimal encoding with optional sign. |
| ToField Int64 | Uses decimal encoding with optional sign. |
| ToField Integer | Uses decimal encoding with optional sign. |
| ToField Word | Uses decimal encoding. |
| ToField Word8 | Uses decimal encoding. |
| ToField Word16 | Uses decimal encoding. |
| ToField Word32 | Uses decimal encoding. |
| ToField Word64 | Uses decimal encoding. |
| ToField ByteString | |
| ToField ByteString | |
| ToField Text | Uses UTF-8 encoding. |
| ToField Text | Uses UTF-8 encoding. |
| ToField [Char] | Uses UTF-8 encoding. |
| ToField a => ToField (Maybe a) |