sv-cassava 0.1 → 0.2
raw patch · 4 files changed
+28/−23 lines, 4 filesdep +sv-coredep −svdep ~validation
Dependencies added: sv-core
Dependencies removed: sv
Dependency ranges changed: validation
Files
- changelog.md +4/−0
- src/Data/Sv/Cassava.hs +6/−15
- sv-cassava.cabal +15/−5
- tests/tests.hs +3/−3
changelog.md view
@@ -1,5 +1,9 @@ # Revision history for sv-cassava +## 0.2 -- 2018-07-19++* Replace sv 0.1 with sv-core 0.1+ ## 0.1 -- 2018-03-14 * First version. Released on an unsuspecting world.
src/Data/Sv/Cassava.hs view
@@ -30,25 +30,16 @@ import Data.ByteString.UTF8 as UTF8 import qualified Data.Csv as Cassava import qualified Data.Csv.Parser as Cassava-import Data.Maybe (mapMaybe)-import Data.Sv-import qualified Data.Sv.Decode as D-import Data.Vector (Vector, (!?))-import Data.Vector.NonEmpty (NonEmptyVector (NonEmptyVector))+import Data.Sv.Structure.Core (Headedness (..))+import Data.Sv.Decode.Core (Decode', DecodeValidation, validateEitherWith)+import qualified Data.Sv.Decode.Core as D+import Data.Validation (bindValidation) import qualified Data.Vector as V-import Text.Escape (Unescaped (Unescaped))-import Text.Space (unspaced)-import Text.Quote (Quote (DoubleQuote)) -- | Use an sv 'Decode' to decode from cassava's 'Cassava.Csv' type. decodeFromCassava :: Decode' ByteString a -> Cassava.Csv -> DecodeValidation ByteString [a] decodeFromCassava d =- traverse (D.promote d) . fs2r . V.toList- where- fs2r :: [Vector Cassava.Field] -> [Record ByteString]- fs2r = mapMaybe (fmap (Record . fmap (unspaced . Quoted DoubleQuote . Unescaped)) . vec2nev)- vec2nev :: Vector b -> Maybe (NonEmptyVector b)- vec2nev v = NonEmptyVector <$> v !? 0 <*> pure (V.drop 1 v)+ traverse (D.promote d) . V.toList -- | Parse a 'Cassava.Csv' from a 'ByteString' using cassava's parser --@@ -56,7 +47,7 @@ -- with the rest of sv. parseCassava :: Cassava.DecodeOptions -> ByteString -> DecodeValidation ByteString Cassava.Csv parseCassava opts =- D.validateEither' (BadParse . UTF8.fromString) . parseOnly (Cassava.csv opts)+ validateEitherWith (D.BadParse . UTF8.fromString) . parseOnly (Cassava.csv opts) -- | Parse a 'Cassava.Csv' from a 'ByteString' using cassava's parser, then -- decode it using the given 'Decode'.
sv-cassava.cabal view
@@ -2,12 +2,11 @@ -- documentation, see http://haskell.org/cabal/users-guide/ name: sv-cassava-version: 0.1+version: 0.2 synopsis: Integration to use sv with cassava's parser description: This package provides functions allowing you to use cassava's parser- together with sv's decoding. You might prefer this to using sv's own- parser if speed is a significant concern.+ together with sv-core's decoding. homepage: https://github.com/qfpl/sv license: BSD3 license-file: LICENCE@@ -18,7 +17,17 @@ build-type: Simple extra-source-files: changelog.md cabal-version: >=1.10+tested-with:+ GHC == 7.10.3+ , GHC == 8.0.2+ , GHC == 8.2.2+ , GHC == 8.4.3+ , GHC == 8.6.1 +source-repository head+ type: git+ location: git@github.com/qfpl/sv.git+ library exposed-modules: Data.Sv.Cassava@@ -27,8 +36,9 @@ , base >=4.8 && <5 , bytestring >= 0.9.1.10 && < 0.11 , cassava >= 0.4.1 && < 0.6- , sv >= 0.1 && < 0.2+ , sv-core >= 0.1 && < 0.2 , utf8-string >= 1 && < 1.1+ , validation , vector >= 0.10 && < 0.13 hs-source-dirs: src@@ -46,7 +56,7 @@ base >=4.8 && <5 , bytestring >= 0.9.1.10 && < 0.11 , cassava >= 0.4.1 && < 0.6- , sv >= 0.1 && < 0.2+ , sv-core >= 0.1 && < 0.2 , sv-cassava , HUnit >= 1.4 && < 1.7 , text >= 1.0 && < 1.3
tests/tests.hs view
@@ -5,9 +5,9 @@ import Control.Monad (when) import Data.ByteString (ByteString) import qualified Data.Csv as Cassava-import Data.Sv import Data.Sv.Cassava-import qualified Data.Sv.Decode as D+import Data.Sv.Structure.Core (Headedness (Headed, Unheaded))+import qualified Data.Sv.Decode.Core as D import Data.Text (Text) import qualified Data.Vector as V import System.Exit (exitFailure)@@ -15,7 +15,7 @@ data TestRow = TestRow Int Double Text deriving (Eq, Show) -testRowDec :: Decode' ByteString TestRow+testRowDec :: D.Decode' ByteString TestRow testRowDec = TestRow <$> D.int <*> D.double <*> D.utf8 bs1 :: ByteString