@@ -151,43 +151,43 @@ import Data.Csv.Types
151151--
152152-- In practice, the return type of 'decode' rarely needs to be given,
153153-- as it can often be inferred from the context.
154- --
154+ --
155155-- Demonstration of reading from a CSV file/ writing to a CSV file
156156-- using the incremental API:
157157--
158158-- > {-#LANGUAGE DeriveGeneric#-}
159159-- > {-#LANGUAGE OverloadedStrings#-}
160160-- > {-#LANGUAGE BangPatterns#-}
161- -- >
161+ -- >
162162-- > import Data.ByteString (ByteString, hGetSome, empty)
163163-- > import qualified Data.ByteString.Lazy as BL
164164-- > import GHC.Generics
165165-- > import Data.Csv.Incremental
166- -- > import Data.Csv (FromRecord, ToRecord)
166+ -- > import Data.Csv (FromRecord, ToRecord)
167167-- > import Data.Monoid ((<>), mempty)
168168-- > import System.IO
169169-- > import System.Exit (exitFailure)
170- -- >
170+ -- >
171171-- > data Person = Person {
172172-- > name :: ByteString,
173173-- > age :: Int
174174-- > } deriving (Show, Eq, Generic)
175- -- >
175+ -- >
176176-- > instance FromRecord Person
177177-- > instance ToRecord Person
178- -- >
178+ -- >
179179-- > persons = [Person "John Doe" 19, Person "Smith" 20]
180- -- >
180+ -- >
181181-- > writeToFile :: IO ()
182182-- > writeToFile = BL.writeFile "persons.csv" $ encode $ foldr (<>) mempty (map encodeRecord persons)
183- -- >
183+ -- >
184184-- > feed :: (ByteString -> Parser Person) -> Handle -> IO (Parser Person)
185185-- > feed k csvFile = do
186186-- > isEof <- hIsEOF csvFile
187187-- > if isEof
188188-- > then return $ k empty
189189-- > else k `fmap` hGetSome csvFile 4096
190- -- >
190+ -- >
191191-- > readFromFile :: IO ()
192192-- > readFromFile = withFile "persons.csv" ReadMode $ \csvFile -> do
193193-- > let loop !_ (Fail _ errMsg) = putStrLn errMsg >> exitFailure
0 commit comments