Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Parse CSV easily using do notation
Haskell
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
Data/CSV
LICENSE
Makefile
Readme.md
Setup.hs
all.do
build.do
clean.do
configure.do
csv-parser.cabal
install.do
tags.do

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)
Something went wrong with that request. Please try again.