geval/src/Lib.hs

26 lines
619 B
Haskell
Raw Normal View History

2015-08-17 23:32:00 +02:00
module Lib
( geval
) where
2015-08-19 22:14:34 +02:00
import Data.Conduit
import Data.Conduit.Combinators as CC
import qualified Data.Conduit.Binary as CB
import qualified Data.Conduit.Text as CT
import Control.Monad.Trans.Resource
import qualified Data.Conduit.List as CL
import Data.Text
import Data.Text.Read as TR
2015-08-17 23:32:00 +02:00
geval :: String -> String -> IO (Double)
geval expectedFilePath outFilePath = do
2015-08-19 22:14:34 +02:00
runResourceT $
CB.sourceFile expectedFilePath
$$ CT.decode CT.utf8
=$= CT.lines
=$= CL.map TR.double
=$= CC.map getValue
=$ CC.sum
getValue :: Either String (Double, Text) -> Double
getValue (Right (x, _)) = x