Created
April 25, 2012 08:50
-
-
Save killerswan/2488286 to your computer and use it in GitHub Desktop.
CSV filtering
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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