The cassava-conduit package

[ Tags: benchmark, bsd3, data, library ] [ Propose Tags ]

Conduit interface for cassava package

PRs welcome.


[Skip to Readme]

Properties

Versions 0.0.1, 0.1.0, 0.2.0, 0.2.1, 0.2.2, 0.3.0, 0.3.1, 0.3.2, 0.3.3, 0.3.4, 0.3.5, 0.3.5.1, 0.4.0.0
Change log CHANGELOG.md
Dependencies array, base (==4.*), bifunctors (>=4.2 && <6), bytestring (==0.10.*), cassava (==0.5.*), conduit (==1.2.*), conduit-extra (==1.1.*), containers, mtl (==2.2.*), text (==1.2.*) [details]
License BSD3
Copyright Copyright (C) 2014-2017 Dom De Re
Author Dom De Re
Maintainer Dom De Re
Category Data
Home page https://github.com/domdere/cassava-conduit
Bug tracker https://github.com/domdere/cassava-conduit/issues
Source repository head: git clone https://github.com/domdere/cassava-conduit
Uploaded Fri Jun 23 16:33:45 UTC 2017 by domdere
Distributions LTSHaskell:0.3.5.1, NixOS:0.4.0.0, Stackage:0.4.0.0, Tumbleweed:0.3.5.1
Downloads 1271 total (29 in the last 30 days)
Rating 0.0 (0 ratings) [clear rating]
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-06-23 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Flags

NameDescriptionDefaultType
small_base

Choose the new, split-up base package.

EnabledAutomatic

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for cassava-conduit-0.4.0.0

[back to package description]

cassava-conduit Build Status Hackage

Conduit interface for cassava package

Streaming to CSV is not 100% complete at this stage, and doesn't support encoding to CSV with a header yet

Example Usage

The examples project

There is a project containing some examples of the usage, but the gist is here:


import Data.Csv
import Data.Conduit
import Data.Csv.Conduit

data InputRecord = ...

instance FromRecord InputRecord where
    ...

data OutputRecord = ...

instance ToRecord OutputRecord where
    ...

decodeOpts :: Word8 -> DecodeOptions

encodeOpts :: Word8 -> EncodeOptions

processInput :: InputRecord -> OutputRecord

-- |
--  A Conduit pipeline that streams from '../exampledata/sampleinput.psv', decodes it from a pipe seperated format,
--  processes it with 'processInput' and the encodes it to pipe seperated format and streams it out to '../exampledata/sampleoutput.psv'
--  The first time it encounters a parse error, it will stop streaming and return the error, dropping any decoded records that came through in that batch also...
--
conduitPipeline :: (MonadError CsvParseError m, MonadResource m) => m ()
conduitPipeline = sourceFile "../exampledata/sampleinput.psv" $$ fromCsv (decodeOpts $ fromIntegral $ ord '|') HasHeader =$= map processInput =$= toCsv (encodeOpts $ fromIntegral $ ord '|') =$= sinkFile "../exampledata/sampleoutput.psv"

main :: IO ()
main = do
    res <- runEitherT $ bimapEitherT showError id $ runResourceT conduitPipeline
    either putStrLn return res

Building the examples project

$ cd examples
$ cabal sandbox init
$ cabal sandbox add-source ../
$ cabal install --only-dependencies
$ cabal build

Building the project

./mafia build

Running Unit Tests

./mafia test