Permalink
Browse files

Tweak API, README

  • Loading branch information...
1 parent 4fe82d7 commit 1eb4137ec4bdfbcfb218f45ae32a9ca9c30af1e2 @ozataman committed Apr 11, 2012
Showing with 34 additions and 16 deletions.
  1. +29 −11 README.markdown
  2. +5 −5 src/Data/CSV/Conduit.hs
View
@@ -47,29 +47,47 @@ regressions or optimization opportunities.
### Usage Examples
-#### Example 1: Basic Operation
+
+#### Example #1: Basics Using Convenience API
{-# LANGUAGE OverloadedStrings #-}
- import Data.Conduit.Text
+ import Data.Conduit
import Data.Conduit.Binary
+ import Data.Conduit.List as CL
+ import Data.CSV.Conduit
+
+ -- Just reverse te columns
+ myProcessor :: Conduit (Row Text) m (Row Text)
+ myProcessor = CL.map reverse
+
+ test :: IO ()
+ test = runResourceT $
+ transformCSV defCSVSettings
+ (sourceFile "input.csv")
+ myProcessor
+ (sinkFile "output.csv")
+
+
+#### Example #2: Basics Using Conduit API
+
+ {-# LANGUAGE OverloadedStrings #-}
+
import Data.Conduit
+ import Data.Conduit.Binary
import Data.CSV.Conduit
+ myProcessor :: Conduit (Row Text) m (Row Text)
+ myProcessor = undefined
+
-- Let's simply stream from a file, parse the CSV, reserialize it
-- and push back into another file.
test :: IO ()
test = runResourceT $
sourceFile "test/BigFile.csv" $=
- decode utf8 $=
- (intoCSV defCSVSettings
- :: forall m. MonadResource m => Conduit Text m (MapRow Text)) $=
- fromCSV defCSVSettings $=
- encode utf8 $$
+ intoCSV defCSVSettings $=
+ myProcessor $=
+ fromCSV defCSVSettings $$
sinkFile "test/BigFileOut.csv"
-and we are done.
-
-
-
View
@@ -16,7 +16,7 @@ module Data.CSV.Conduit
, Row
-- * Convenience Functions
, readCSVFile
- , transformCSVFile
+ , transformCSV
, mapCSVFile
) where
@@ -226,7 +226,7 @@ mapCSVFile
-- ^ Output file
-> m ()
mapCSVFile set f fi fo =
- transformCSVFile set (sourceFile fi) (C.concatMap f) (sinkFile fo)
+ transformCSV set (sourceFile fi) (C.concatMap f) (sinkFile fo)
-------------------------------------------------------------------------------
@@ -240,8 +240,8 @@ mapCSVFile set f fi fo =
--
-- Example - map a function over the rows of a CSV file:
--
--- > transformCSVFile set (sourceFile inFile) (C.map f) (sinkFile outFile)
-transformCSVFile
+-- > transformCSV set (sourceFile inFile) (C.map f) (sinkFile outFile)
+transformCSV
:: (MonadResource m, CSV s a, CSV s' b)
=> CSVSettings
-- ^ Settings to be used for input and output
@@ -252,7 +252,7 @@ transformCSVFile
-> Sink s' m ()
-- ^ A raw stream data sink. Ex: 'sinkFile outFile'
-> m ()
-transformCSVFile set source c sink =
+transformCSV set source c sink =
source $=
intoCSV set $=
c $=

0 comments on commit 1eb4137

Please sign in to comment.