Parse CSV easily using do notation
Haskell Nix Makefile
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Data/CSV
LICENSE
Makefile
Readme.md
Setup.hs
csv-parser.cabal
csv-parser.nix

Readme.md

Data.CSV.Parser

Easily parse CSV files

Example

import Data.CSV.Parser
import Control.Applicative

type Parser a = FromCSV String a

data Track = Track { trackCatId :: String
                   , trackNum   :: Int
                   , trackTitle :: String
                   } deriving (Show)

trackParser :: Parser Track
trackParser = do
  first <- columnInd 0
  catId <- column "CatalogId"
  track <- read <$> column "Track"
  title <- column "Title"
  return $ Track catId track title

-- Or, alternatively, in Applicative style:
trackParser' :: Parser Track
trackParser' = Track <$> column "CatalogId"
                     <*> fmap read (column "Track")
                     <*> column "Title"

main = do
  Right csv <- parseCSVFromFile "stuff.csv"
  mapM_ print (convert trackParser csv)