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 = [(Name, Name)] -> NamedRecord
forall k v. (Eq k, Hashable k) => [(k, v)] -> HashMap k v
HM.fromList ([(Name, Name)] -> NamedRecord)
-> (Vector (Name, Name) -> [(Name, Name)])
-> Vector (Name, Name)
-> NamedRecord
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Vector (Name, Name) -> [(Name, Name)]
forall a. Vector a -> [a]
V.toList (Vector (Name, Name) -> NamedRecord)
-> Vector (Name, Name) -> NamedRecord
forall a b. (a -> b) -> a -> b
$ Header -> Header -> Vector (Name, Name)
forall a b. Vector a -> Vector b -> Vector (a, b)
V.zip Header
hdr Header
v
data =
|