Safe Haskell | Safe-Infered |
---|
Data.CSV.Conduit
Contents
- class CSVeable s r where
- rowToStr :: CSVSettings -> r -> s
- intoCSV :: MonadResource m => CSVSettings -> Conduit s m r
- fromCSV :: MonadResource m => CSVSettings -> Conduit r m s
- data CSVSettings = CSVS {
- csvSep :: !Char
- csvQuoteChar :: !(Maybe Char)
- csvOutputQuoteChar :: !(Maybe Char)
- csvOutputColSep :: !Char
- defCSVSettings :: CSVSettings
- type MapRow a = Map a a
- type Row a = [a]
- readCSVFile :: (MonadUnsafeIO m, MonadThrow m, MonadBaseControl IO m, MonadIO m, CSVeable ByteString a) => CSVSettings -> FilePath -> m [a]
- mapCSVFile :: (MonadIO m, MonadUnsafeIO m, MonadThrow m, MonadBaseControl IO m, CSVeable ByteString a, CSVeable ByteString b) => CSVSettings -> (a -> b) -> FilePath -> FilePath -> m ()
Documentation
class CSVeable s r whereSource
Represents types r
that can be converted from an underlying
stream of type s
.
Example processing using MapRow Text isntance:
test :: IO () test = runResourceT $ sourceFile test/BigFile.csv $= decode utf8 $= intoCSV defCSVSettings $= myMapRowProcessingConduit $= fromCSV defCSVSettings $= encode utf8 $$ sinkFile test/BigFileOut.csv
Methods
rowToStr :: CSVSettings -> r -> sSource
Convert a CSV row into strict ByteString equivalent.
intoCSV :: MonadResource m => CSVSettings -> Conduit s m rSource
Turn a stream of s
into a stream of CSV row type
fromCSV :: MonadResource m => CSVSettings -> Conduit r m sSource
Turn a stream of CSV row type back into a stream of s
Instances
(CSVeable s (Row s'), Ord s', IsString s) => CSVeable s (MapRow s') | Generic |
CSVeable ByteString (Row ByteString) |
|
CSVeable ByteString (Row Text) |
|
CSVeable Text (Row Text) |
data CSVSettings Source
Settings for a CSV file. This library is intended to be flexible and offer a way to process the majority of text data files out there.
Constructors
CSVS | |
Fields
|
Instances
defCSVSettings :: CSVSettingsSource
Default settings for a CSV file.
csvSep = ',' csvQuoteChar = Just '"' csvOutputQuoteChar = Just '"' csvOutputColSep = ','
Convenience Functions
readCSVFile :: (MonadUnsafeIO m, MonadThrow m, MonadBaseControl IO m, MonadIO m, CSVeable ByteString a) => CSVSettings -> FilePath -> m [a]Source
Read the entire contents of a CSV file into memory
Arguments
:: (MonadIO m, MonadUnsafeIO m, MonadThrow m, MonadBaseControl IO m, CSVeable ByteString a, CSVeable ByteString b) | |
=> CSVSettings | Settings to use both for input and output |
-> (a -> b) | A mapping function |
-> FilePath | Input file |
-> FilePath | Output file |
-> m () |
Map over the rows of a CSV file. Don't be scared by the type signature, this can just run in IO.