Skip to content

Instantly share code, notes, and snippets.

@mxswd
Created March 11, 2014 15:02
Show Gist options
  • Save mxswd/9487642 to your computer and use it in GitHub Desktop.
Save mxswd/9487642 to your computer and use it in GitHub Desktop.
Using csv-conduit to answer "How many kms of fences are on public land in the Gold Coast?"
name: fences
version: 0.1.0.0
-- synopsis:
-- description:
license: BSD3
license-file: LICENSE
author: Maxwell Swadling
maintainer: [email protected]
-- copyright:
-- category:
build-type: Simple
-- extra-source-files:
cabal-version: >=1.10
executable bigdata
main-is: Fences.hs
-- other-modules:
-- other-extensions:
build-depends: base >=4.6 && <4.7, conduit >=1.0 && <1.1, csv-conduit == 0.5.1, text >= 1.1 && < 1.2
-- hs-source-dirs:
default-language: Haskell2010
import Data.Conduit (Conduit, runResourceT, ($$), ($=), (=$=))
import Data.Conduit.Binary (sourceFile)
import Data.Conduit.List as CL (consume, map)
import Data.CSV.Conduit (Row, intoCSV, defCSVSettings)
import Data.Text (Text, unpack)
-- data source: http://data.gov.au/dataset/fences-on-public-land
mkValuable :: Monad m => Conduit (Row Text) m Double
mkValuable = CL.map extractVal
where
extractVal = read . unpack . flip (!!) 7
getBig :: IO [Double]
getBig = fmap (drop 1) -- the power of lazy
$ runResourceT
$ sourceFile "fences.csv"
$= intoCSV defCSVSettings
$= mkValuable
$$ consume
main = do
xs <- getBig
putStrLn $ show (round (sum xs / 1000)) ++ "km of fences"
import Distribution.Simple
main = defaultMain
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment