module Data.Csv.Types
(
Csv
, Record
, Header
, Name
, NamedRecord
, Field
, toNamedRecord
, HasHeader(..)
) where
import qualified Data.ByteString as S
import qualified Data.HashMap.Strict as HM
import Data.Vector (Vector)
import qualified Data.Vector as V
type Csv = Vector Record
type Record = Vector Field
type = Vector Name
type Name = S.ByteString
type NamedRecord = HM.HashMap S.ByteString S.ByteString
type Field = S.ByteString
toNamedRecord :: Header -> Record -> NamedRecord
toNamedRecord :: Header -> Header -> NamedRecord
toNamedRecord Header
hdr Header
v = [(ByteString, ByteString)] -> NamedRecord
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HM.fromList ([(ByteString, ByteString)] -> NamedRecord)
-> (Vector (ByteString, ByteString) -> [(ByteString, ByteString)])
-> Vector (ByteString, ByteString)
-> NamedRecord
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (ByteString, ByteString) -> [(ByteString, ByteString)]
forall a. Vector a -> [a]
V.toList (Vector (ByteString, ByteString) -> NamedRecord)
-> Vector (ByteString, ByteString) -> NamedRecord
forall a b. (a -> b) -> a -> b
$ Header -> Header -> Vector (ByteString, ByteString)
forall a b. Vector a -> Vector b -> Vector (a, b)
V.zip Header
hdr Header
v
data =
|