implemented slurpLabelledCSV

This commit is contained in:
Jonathan Lamothe 2022-04-21 22:23:48 -04:00
parent 35130eeae1
commit 51784123cd

View File

@ -29,6 +29,7 @@ module Data.CSV.Sip (
-- * Read an entire CSV file -- * Read an entire CSV file
slurpCSV, slurpCSV,
slurpRawCSV, slurpRawCSV,
slurpLabelledCSV,
-- * Conduits -- * Conduits
labelFields, labelFields,
decodeRows, decodeRows,
@ -74,6 +75,15 @@ slurpRawCSV
-> m [[BS.ByteString]] -> m [[BS.ByteString]]
slurpRawCSV file = runConduit $ sourceFile file .| decodeRawRows .| consume slurpRawCSV file = runConduit $ sourceFile file .| decodeRawRows .| consume
-- | read an entire CSV file with a header
slurpLabelledCSV
:: MonadResource m
=> FilePath
-- ^ the path to the file to read
-> m [M.Map T.Text T.Text]
slurpLabelledCSV file = runConduit $
sourceFile file .| decodeRows .| labelFields .|consume
-- | read a CSV stream, using the first row as a header containing -- | read a CSV stream, using the first row as a header containing
-- field labels -- field labels
labelFields :: (Monad m, Ord a) => ConduitT [a] (M.Map a a) m () labelFields :: (Monad m, Ord a) => ConduitT [a] (M.Map a a) m ()