Skip to content

Commit

Permalink
support(style): Rename parsing and use =<< instead of >>=
Browse files Browse the repository at this point in the history
  • Loading branch information
gillchristian committed May 3, 2019
1 parent 5f6f729 commit 818c554
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
18 changes: 11 additions & 7 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ module Main
) where

import qualified Data.Aeson as Aeson
import Parsing (entries)
import Parsing (parseEntries)
import qualified System.Environment as Env
import qualified System.IO as Sys

processInput :: String -> IO Aeson.Value
processInput file = Aeson.toJSON . entries <$> readFile file
putStderr :: String -> IO ()
putStderr = Sys.hPutStrLn Sys.stderr

doStuff :: FilePath -> FilePath -> IO ()
doStuff input output =
Aeson.encodeFile output =<< Aeson.toJSON . parseEntries <$> readFile input

main :: IO ()
main = do
(sts:out:_) <- Env.getArgs -- TODO handle missing files
Sys.hPutStrLn Sys.stderr $ "Processing statements from: \"" ++ sts ++ "\""
processInput sts >>= Aeson.encodeFile out
Sys.hPutStrLn Sys.stderr $ "Data written to: \"" ++ out ++ "\""
(input:output:_) <- Env.getArgs -- TODO handle missing files
putStderr $ "Processing statements from: \"" ++ input ++ "\""
doStuff input output
putStderr $ "Data written to: \"" ++ input ++ "\""
6 changes: 3 additions & 3 deletions src/Parsing.hs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Parsing
( entries
( parseEntries
) where

import qualified Data.Char as C
Expand Down Expand Up @@ -39,6 +39,6 @@ entryOfRow (account, cur, d1, before', after', d2, deb, desc) =
before'' = readAmount before'
balance' = Balance {before = before'', after = after'', debit = debit'}

entries :: String -> [Entry]
entries =
parseEntries :: String -> [Entry]
parseEntries =
map entryOfRow . M.mapMaybe (row . S.split "\t" . S.strip) . lines . S.strip
2 changes: 1 addition & 1 deletion todo.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
- [ ] parse dates
- [ ] extract useful data from description
- [ ] group by months & categories
- [x] parse dates
- [x] split in modules
- [x] use stack file

Expand Down

0 comments on commit 818c554

Please sign in to comment.