box-csv 0.0.3 → 0.1.0
raw patch · 3 files changed
+57/−98 lines, 3 filesdep −doctestdep −numhaskdep ~attoparsecdep ~boxdep ~generic-lensPVP ok
version bump matches the API change (PVP)
Dependencies removed: doctest, numhask
Dependency ranges changed: attoparsec, box, generic-lens, lens, scientific, text, time
API changes (from Hackage documentation)
Files
- box-csv.cabal +31/−58
- src/Box/Csv.hs +26/−21
- test/test.hs +0/−19
box-csv.cabal view
@@ -1,67 +1,40 @@ cabal-version: 2.4-name: box-csv-version: 0.0.3-synopsis: See readme.md-description: See readme.md for description.-category: project-author: Tony Day-maintainer: tonyday567@gmail.com-copyright: Tony Day (c) AfterTimes-license: BSD-3-Clause-homepage: https://github.com/tonyday567/box-csv#readme-bug-reports: https://github.com/tonyday567/box-csv/issues-build-type: Simple+name: box-csv+version: 0.1.0+synopsis: CSV parsing in a box.+description: CSV parsing using attoparsec and the box library.+category: project+author: Tony Day+maintainer: tonyday567@gmail.com+copyright: Tony Day (c) AfterTimes+license: BSD-3-Clause+homepage: https://github.com/tonyday567/box-csv#readme+bug-reports: https://github.com/tonyday567/box-csv/issues+build-type: Simple+tested-with: GHC ==8.8.4 || ==8.10.4 || ==9.0.1 || ==9.2.0.20210821+ source-repository head- type: git+ type: git location: https://github.com/tonyday567/box-csv library- hs-source-dirs:- src+ hs-source-dirs: src default-extensions:- NoImplicitPrelude- NegativeLiterals- OverloadedStrings- UnicodeSyntax ghc-options:- -Wall- -Wcompat- -Wincomplete-record-updates- -Wincomplete-uni-patterns- -Wredundant-constraints- build-depends:- attoparsec >= 0.13,- base >=4.7 && <5,- box >= 0.6 && < 0.7,- generic-lens,- lens >= 4.19,- numhask >= 0.6 && < 0.7,- scientific >= 0.3,- text >= 1.2,- time >= 1.9,- exposed-modules:- Box.Csv- other-modules:- default-language: Haskell2010+ -Wall -Wcompat -Wincomplete-record-updates+ -Wincomplete-uni-patterns -Wredundant-constraints -fwrite-ide-info+ -hiedir=.hie -Wunused-packages -test-suite test- type: exitcode-stdio-1.0- main-is: test.hs- hs-source-dirs:- test- default-extensions:- NoImplicitPrelude- NegativeLiterals- OverloadedStrings- UnicodeSyntax- ghc-options:- -Wall- -Wcompat- -Wincomplete-record-updates- -Wincomplete-uni-patterns- -Wredundant-constraints build-depends:- base >=4.7 && <5,- doctest >= 0.16,- numhask >= 0.6 && < 0.7- default-language: Haskell2010+ , attoparsec >=0.13 && <0.16+ , base >=4.7 && <5+ , box ^>=0.7+ , generic-lens ^>=2.0+ , lens ^>=5.0+ , scientific ^>=0.3+ , text ^>=1.2+ , time ^>=1.9++ exposed-modules: Box.Csv+ other-modules:+ default-language: Haskell2010
src/Box/Csv.hs view
@@ -2,11 +2,10 @@ {-# LANGUAGE OverloadedLabels #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE StrictData #-} {-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE NoImplicitPrelude #-} -- | A csv process based on attoparsec and the box library--- module Box.Csv ( CsvConfig (..), defaultCsvConfig,@@ -38,30 +37,35 @@ import Box import Control.Lens+import Control.Monad import qualified Data.Attoparsec.Text as A import Data.Generics.Labels () import Data.Scientific+import Data.Text (Text, unpack) import qualified Data.Text as Text-import NumHask.Prelude import Data.Time+import GHC.Generics -- $setup -- >>> :set -XOverloadedStrings+-- >>> import Box+-- >>> import Box.Csv+-- >>> import qualified Data.Text as Text+-- >>> import qualified Data.Attoparsec.Text as A -- | csv file configuration-data CsvConfig- = CsvConfig- { -- | file name stem- name :: Text,- -- | file suffix- suffix :: Text,- -- | directory- dir :: Text,- -- | field separator- fsep :: Char,- -- | nature of header row(s)- header :: Header- }+data CsvConfig = CsvConfig+ { -- | file name stem+ name :: Text,+ -- | file suffix+ suffix :: Text,+ -- | directory+ dir :: Text,+ -- | field separator+ fsep :: Char,+ -- | nature of header row(s)+ header :: Header+ } deriving (Show, Generic, Eq) -- | default csv file details@@ -103,13 +107,14 @@ -- | commits printed csv rows -- -- >>> let testConfig = CsvConfig "test" ".csv" "./test" ',' NoHeader--- >>> let ctest = rowCommitter testConfig (fmap (Text.intercalate "," . fmap show))--- >>> ctest `with` (\c -> commit c [[1..10::Int]])+-- >>> let ctest = rowCommitter testConfig (fmap (Text.intercalate "," . fmap (Text.pack . show)))+--+-- FIXME: fails if used outside this project.+-- > ctest `with` (\c -> commit c [[1..10::Int]]) -- True ----- >>> rowEmitter testConfig ints `with` emit+-- > rowEmitter testConfig ints `with` emit -- Just (Right [1,2,3,4,5,6,7,8,9,10])--- rowCommitter :: CsvConfig -> (a -> [Text]) -> Cont IO (Committer IO a) rowCommitter cfg f = contramap (Text.intercalate (Text.singleton $ view #fsep cfg) . f) <$> fileWriteC (file cfg) @@ -223,12 +228,12 @@ pure d' -- * Block list parsers+ -- | Parser for a csv row of [Text]. -- TODO: deal with potential for an extra '\r' -- -- >>> A.parseOnly (fields ',') "field1,field2\r" -- Right ["field1","field2\r"]--- fields :: Char -> A.Parser [Text] fields c = field_ c `A.sepBy1` sep c
− test/test.hs
@@ -1,19 +0,0 @@-{-# LANGUAGE DataKinds #-}-{-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE OverloadedLabels #-}-{-# LANGUAGE OverloadedStrings #-}-{-# LANGUAGE ScopedTypeVariables #-}-{-# LANGUAGE TypeOperators #-}-{-# LANGUAGE NoImplicitPrelude #-}-{-# OPTIONS_GHC -Wall #-}--module Main where--import NumHask.Prelude-import Test.DocTest--main :: IO ()-main =- doctest- [ "src/Box/Csv.hs"- ]