cassava-streams 0.1.0.0 → 0.1.1.0
raw patch · 4 files changed
+33/−19 lines, 4 filesdep ~bytestringdep ~io-streamsdep ~vectorPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: bytestring, io-streams, vector
API changes (from Hackage documentation)
+ System.IO.Streams.Csv.Tutorial: time :: Item -> Maybe Double
- System.IO.Streams.Csv.Tutorial: Item :: String -> TState -> Item
+ System.IO.Streams.Csv.Tutorial: Item :: String -> TState -> Maybe Double -> Item
Files
- CHANGELOG +5/−0
- cassava-streams.cabal +6/−5
- src/System/IO/Streams/Csv/Decode.hs +14/−9
- src/System/IO/Streams/Csv/Tutorial.hs +8/−5
CHANGELOG view
@@ -1,3 +1,8 @@+2014-11-11 Peter Jones <pjones@devalot.com>++ * System/IO/Streams/Csv/Decode.hs added more descriptive error messages.+ * cassava-streams bumped version number (0.1.1.0).+ 2014-04-30 Peter Jones <pjones@devalot.com> * cassava-streams initial release (version 0.1.0.0).
cassava-streams.cabal view
@@ -1,6 +1,6 @@ -------------------------------------------------------------------------------- name: cassava-streams-version: 0.1.0.0+version: 0.1.1.0 synopsis: io-streams interface for the cassava CSV library. license: BSD3 license-file: LICENSE@@ -10,7 +10,7 @@ category: Data, Text, CSV, IO-Streams build-type: Simple cabal-version: >=1.10-tested-with: GHC==7.8.2+tested-with: GHC==7.8.2, GHC==7.8.3 homepage: https://github.com/pjones/cassava-streams bug-reports: https://github.com/pjones/cassava-streams/issues description:@@ -33,6 +33,7 @@ -------------------------------------------------------------------------------- flag maintainer description: Enable settings for the package maintainer.+ manual: True default: False --------------------------------------------------------------------------------@@ -58,10 +59,10 @@ ghc-options: -Werror build-depends: base >= 4.6 && < 5.0- , bytestring >= 0.10 && < 1.0+ , bytestring >= 0.10 && < 0.11 , cassava >= 0.4 && < 0.5- , io-streams >= 1.1.0 && < 2.0- , vector >= 0.10 && < 1.0+ , io-streams >= 1.1 && < 1.2+ , vector >= 0.10 && < 0.11 -------------------------------------------------------------------------------- executable tutorial
src/System/IO/Streams/Csv/Decode.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE DeriveDataTypeable #-}+{-# LANGUAGE ScopedTypeVariables #-} {- @@ -116,12 +117,12 @@ case upstream of Nothing -> return Nothing- Just (Left err) -> bomb err+ Just (Left err) -> bomb ("invalid CSV row: " ++ err) Just (Right x) -> return (Just x) -------------------------------------------------------------------------------- -- | Internal function which feeds data to the CSV parser.-dispatch :: IORef [Either String a]+dispatch :: forall a. IORef [Either String a] -- ^ List of queued CSV records. -> IORef (Maybe (Parser a)) -- ^ Current CSV parser state.@@ -137,9 +138,10 @@ parser <- readIORef parserRef case parser of Nothing -> return Nothing- Just (Fail _ e) -> bomb e- Just (Many xs f) -> more f >> feed xs- Just (Done xs ) -> writeIORef parserRef Nothing >> feed xs+ Just (Fail _ e) -> bomb ("input data malformed: " ++ e)+ Just (Many [] f) -> more f+ Just (Many xs f) -> writeIORef parserRef (Just $ Many [] f) >> feed xs+ Just (Done xs ) -> writeIORef parserRef Nothing >> feed xs (x:xs) -> do writeIORef queueRef xs@@ -148,12 +150,15 @@ where -- Send more data to the CSV parser. If there is no more data -- from upstream then send an empty @ByteString@.- more f = Streams.read input >>=- writeIORef parserRef . Just . maybe (f BS.empty) f+ more :: (ByteString -> Parser a) -> IO (Maybe (Either String a))+ more f = do bs <- Streams.read input+ writeIORef parserRef (Just $ maybe (f BS.empty) f bs)+ dispatch queueRef parserRef input -- Feed records downstream.- feed xs = writeIORef queueRef xs >>- dispatch queueRef parserRef input+ feed :: [Either String a] -> IO (Maybe (Either String a))+ feed xs = do writeIORef queueRef xs+ dispatch queueRef parserRef input -------------------------------------------------------------------------------- -- | Throw an exception.
src/System/IO/Streams/Csv/Tutorial.hs view
@@ -41,18 +41,21 @@ -------------------------------------------------------------------------------- -- | A to-do item. data Item = Item- { title :: String- , state :: TState+ { title :: String -- ^ Title.+ , state :: TState -- ^ State.+ , time :: Maybe Double -- ^ Seconds taken to complete. } deriving (Show, Eq) instance FromNamedRecord Item where parseNamedRecord m = Item <$> m .: "Title" <*> m .: "State"+ <*> m .: "Time" instance ToNamedRecord Item where- toNamedRecord (Item t s) =+ toNamedRecord (Item t s tm) = namedRecord [ "Title" .= t , "State" .= s+ , "Time" .= tm ] --------------------------------------------------------------------------------@@ -105,7 +108,7 @@ -- A stream to write items into. They will be converted to CSV. output <- Streams.handleToOutputStream outH >>=- encodeStreamByName (V.fromList ["State", "Title"])+ encodeStreamByName (V.fromList ["State", "Time", "Title"]) -- Connect the input and output streams. Streams.connect input output@@ -132,7 +135,7 @@ -- A stream to write items into. They will be converted to CSV. output <- Streams.handleToOutputStream outH >>=- encodeStreamByName (V.fromList ["State", "Title"])+ encodeStreamByName (V.fromList ["State", "Time", "Title"]) -- Connect the input and output streams. Streams.connect input output