implemented slurpCSV
This commit is contained in:
parent
76cea1e051
commit
8533e84caa
|
@ -26,6 +26,9 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
{-# LANGUAGE LambdaCase, OverloadedStrings #-}
|
||||
|
||||
module Data.CSV.Sip (
|
||||
-- * Read an entire CSV file
|
||||
slurpCSV,
|
||||
-- * Conduits
|
||||
labelFields,
|
||||
decodeRows,
|
||||
decodeRawRows,
|
||||
|
@ -33,18 +36,33 @@ module Data.CSV.Sip (
|
|||
toBytes,
|
||||
) where
|
||||
|
||||
import Conduit (ConduitT, await, mapC, yield, (.|))
|
||||
import Conduit
|
||||
( ConduitT
|
||||
, MonadResource
|
||||
, await
|
||||
, mapC
|
||||
, runConduit
|
||||
, sourceFile
|
||||
, yield
|
||||
, (.|)
|
||||
)
|
||||
import Control.Monad (unless)
|
||||
import Control.Monad.Trans.Class (lift)
|
||||
import Control.Monad.Trans.State (StateT, evalStateT, get, gets, modify)
|
||||
import qualified Data.ByteString as BS
|
||||
import Data.Conduit.List (consume)
|
||||
import qualified Data.Map as M
|
||||
import Data.Maybe (fromMaybe)
|
||||
import qualified Data.Text as T
|
||||
import Data.Text.Encoding (decodeUtf8')
|
||||
import Data.Word (Word8)
|
||||
|
||||
-- | read a CSV stream, using the first row as a header containing field labels
|
||||
-- | read an entire CSV file
|
||||
slurpCSV :: MonadResource m => FilePath -> m [[T.Text]]
|
||||
slurpCSV file = runConduit $ sourceFile file .| decodeRows .| consume
|
||||
|
||||
-- | read a CSV stream, using the first row as a header containing
|
||||
-- field labels
|
||||
labelFields :: (Monad m, Ord a) => ConduitT [a] (M.Map a a) m ()
|
||||
labelFields = await >>= \case
|
||||
Just headers -> labelLoop headers
|
||||
|
|
Loading…
Reference in New Issue
Block a user