You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A CSV parsing and encoding library optimized for ease of use and high
performance.
Usage example
Here's the two second crash course in using the library. Given a CSV
file with this content:
John Doe,50000
Jane Doe,60000
here's how you'd process it record-by-record:
{-# LANGUAGE ScopedTypeVariables #-}
importqualifiedData.ByteString.LazyasBLimportData.CsvimportqualifiedData.VectorasVmain::IO()
main =do
csvData <-BL.readFile"salaries.csv"case decode NoHeader csvData ofLeft err ->putStrLn err
Right v ->V.forM_ v $\ (name, salary ::Int) ->putStrLn$ name ++" earns "++show salary ++" dollars"
If you want to parse a file that includes a header, like this one
name,salary
John Doe,50000
Jane Doe,60000
use decodeByName:
{-# LANGUAGE OverloadedStrings #-}
importControl.ApplicativeimportqualifiedData.ByteString.LazyasBLimportData.CsvimportqualifiedData.VectorasVdataPerson=Person{name::!String
, salary::!Int}instanceFromNamedRecordPersonwhere
parseNamedRecord r =Person<$> r .:"name"<*> r .:"salary"main::IO()
main =do
csvData <-BL.readFile"salaries.csv"case decodeByName csvData ofLeft err ->putStrLn err
Right (_, v) ->V.forM_ v $\ p ->putStrLn$ name p ++" earns "++show (salary p) ++" dollars"