{-

This file is part of the package csv-refactor. It is subject to the
license terms in the LICENSE file found in the top-level directory of
this distribution and at:

  https://github.com/boulder-haskell-programmers/csv-refactor

No part of the csv-refactor package, including this file, may be
copied, modified, propagated, or distributed except according to the
terms contained in the LICENSE file.

-}

--------------------------------------------------------------------------------
module PersonA where

--------------------------------------------------------------------------------
import Control.Applicative
import Data.Csv
import qualified Data.Vector as V

--------------------------------------------------------------------------------
data Person = Person
  { name   :: String
  , age    :: Int
  , height :: Int
  }

--------------------------------------------------------------------------------
header :: Header
header = V.fromList [ "name"
                    , "age"
                    , "height"
                    ]

--------------------------------------------------------------------------------
instance FromNamedRecord Person where
  parseNamedRecord row =
    Person <$> row .: "name"
           <*> row .: "age"
           <*> row .: "height"

--------------------------------------------------------------------------------
instance ToNamedRecord Person where
  toNamedRecord person =
    namedRecord [ "name"   .= name person
                , "age"    .= age person
                , "height" .= height person
                ]
