Safe Haskell | None |
---|---|
Language | Haskell2010 |
This module allows constant-space CSV parsing.
It feeds ByteString
s into cassavas incremental CSV parser to attain true
constant-space record streaming.
- decode :: (Monad m, FromRecord a) => HasHeader -> Producer ByteString m () -> Producer (Either String a) m ()
- decodeWith :: (Monad m, FromRecord a) => DecodeOptions -> HasHeader -> Producer ByteString m () -> Producer (Either String a) m ()
- decodeByName :: (Monad m, FromNamedRecord a) => Producer ByteString m () -> Producer (Either String a) m ()
- decodeByNameWith :: (Monad m, FromNamedRecord a) => DecodeOptions -> Producer ByteString m () -> Producer (Either String a) m ()
- feedParser :: Monad m => Parser a -> Producer ByteString m () -> Producer (Either String a) m ()
- feedHeaderParser :: Monad m => HeaderParser (Parser a) -> Producer ByteString m () -> Producer (Either String a) m ()
- encode :: (Monad m, ToRecord a) => Pipe a ByteString m r
- encodeWith :: (Monad m, ToRecord a) => EncodeOptions -> Pipe a ByteString m r
- encodeByName :: (Monad m, ToNamedRecord a) => Header -> Pipe a ByteString m r
- encodeByNameWith :: (Monad m, ToNamedRecord a) => EncodeOptions -> Header -> Pipe a ByteString m r
- module Data.Csv
- data HasHeader :: *
Example
Heres a simple example that reads from stdin and writes to a file
@ import Pipes.Safe (runSafeT) import qualified Pipes.Safe.Prelude as PS import qualified Pipes.ByteString as PB import Data.Vector (fromList) import System.IO (IOMode(WriteMode))
data Person = Person String Int deriving (Show)
instance FromNamedRecord Person where parseNamedRecord p = Person <$> p .: "name" <*> p .: "age"
personRec ~(Person name age) = ["name" .= name, "age" .= age]
instance ToNamedRecord Person where
toNamedRecord = namedRecord
. personRec
persons :: Monad m => Producer ByteString m () -> Producer Person m ()
persons p = decodeByName
p >-> right
Decode records
decode :: (Monad m, FromRecord a) => HasHeader -> Producer ByteString m () -> Producer (Either String a) m () Source
Equivalent to
.decodeWith
defaultDecodeOptions
decodeWith :: (Monad m, FromRecord a) => DecodeOptions -> HasHeader -> Producer ByteString m () -> Producer (Either String a) m () Source
Create a Producer
that takes a ByteString
Producer
as input,
producing either errors or FromRecord
s.
Decode named records
decodeByName :: (Monad m, FromNamedRecord a) => Producer ByteString m () -> Producer (Either String a) m () Source
Equivalent to
.decodeByNameWith
defaultDecodeOptions
decodeByNameWith :: (Monad m, FromNamedRecord a) => DecodeOptions -> Producer ByteString m () -> Producer (Either String a) m () Source
Create a Producer
that takes a ByteString
Producer
as input,
producing either errors or FromNamedRecord
s.
Decode parsed records
feedParser :: Monad m => Parser a -> Producer ByteString m () -> Producer (Either String a) m () Source
Create a Record Producer
by feeding ByteString
s into a Parser
feedHeaderParser :: Monad m => HeaderParser (Parser a) -> Producer ByteString m () -> Producer (Either String a) m () Source
Create a NamedRecord Producer
by feeding ByteString
s into a Parser
Encode records
encode :: (Monad m, ToRecord a) => Pipe a ByteString m r Source
Encode records as strict ByteString
s
encodeWith :: (Monad m, ToRecord a) => EncodeOptions -> Pipe a ByteString m r Source
Encode records as strict ByteString
s
Encode named records
encodeByName :: (Monad m, ToNamedRecord a) => Header -> Pipe a ByteString m r Source
Encode named records as strict ByteString
s
encodeByNameWith :: (Monad m, ToNamedRecord a) => EncodeOptions -> Header -> Pipe a ByteString m r Source
Encode named records as strict ByteString
s
Re-exports
Data.Csv re-exports common types and operators:
FromRecord
,FromNamedRecord
,ToRecord
,ToNamedRecord
ToField
,FromField
Record
,Field
,NamedRecord
- '(.!)', '(.:)', '(.=)'
DecodeOptions
,defaultDecodeOptions
module Data.Csv