Skip to content

Instantly share code, notes, and snippets.

@killerswan
Created April 25, 2012 08:50
Show Gist options
  • Save killerswan/2488286 to your computer and use it in GitHub Desktop.
Save killerswan/2488286 to your computer and use it in GitHub Desktop.
CSV filtering
import Text.CSV
loadCSV =
do
eitherRecs <- parseCSVFromFile "sample.csv"
let records = case eitherRecs
of Left e -> error . show $ e
Right recs -> recs
return records
main =
do
recs <- loadCSV
putStrLn . printCSV . filter lessThan7 $ recs
lessThan7 xs =
length xs == 4 && field1' < 7
where
field1 :: String
field1 = xs !! 1
field1' = read field1 :: Int
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment