lib: rename get/setIndex, add increment fn
This commit is contained in:
parent
80e8caebe7
commit
7e84b4d643
@ -178,11 +178,17 @@ getAccountAliases = fmap ctxAliases getState
|
|||||||
clearAccountAliases :: Monad m => JournalParser m ()
|
clearAccountAliases :: Monad m => JournalParser m ()
|
||||||
clearAccountAliases = modifyState (\(ctx@Ctx{..}) -> ctx{ctxAliases=[]})
|
clearAccountAliases = modifyState (\(ctx@Ctx{..}) -> ctx{ctxAliases=[]})
|
||||||
|
|
||||||
getIndex :: Monad m => JournalParser m Integer
|
getTransactionIndex :: Monad m => JournalParser m Integer
|
||||||
getIndex = fmap ctxTransactionIndex getState
|
getTransactionIndex = fmap ctxTransactionIndex getState
|
||||||
|
|
||||||
setIndex :: Monad m => Integer -> JournalParser m ()
|
setTransactionIndex :: Monad m => Integer -> JournalParser m ()
|
||||||
setIndex i = modifyState (\ctx -> ctx{ctxTransactionIndex=i})
|
setTransactionIndex i = modifyState (\ctx -> ctx{ctxTransactionIndex=i})
|
||||||
|
|
||||||
|
-- | Increment the transaction index by one and return the new value.
|
||||||
|
incrementTransactionIndex :: Monad m => JournalParser m Integer
|
||||||
|
incrementTransactionIndex = do
|
||||||
|
modifyState (\ctx -> ctx{ctxTransactionIndex=ctxTransactionIndex ctx + 1})
|
||||||
|
getTransactionIndex
|
||||||
|
|
||||||
journalAddFile :: (FilePath,String) -> Journal -> Journal
|
journalAddFile :: (FilePath,String) -> Journal -> Journal
|
||||||
journalAddFile f j@Journal{files=fs} = j{files=fs++[f]}
|
journalAddFile f j@Journal{files=fs} = j{files=fs++[f]}
|
||||||
|
|||||||
@ -416,9 +416,8 @@ transactionp = do
|
|||||||
comment <- try followingcommentp <|> (newline >> return "")
|
comment <- try followingcommentp <|> (newline >> return "")
|
||||||
let tags = commentTags comment
|
let tags = commentTags comment
|
||||||
postings <- postingsp (Just date)
|
postings <- postingsp (Just date)
|
||||||
i' <- (+1) <$> getIndex
|
idx <- incrementTransactionIndex
|
||||||
setIndex i'
|
return $ txnTieKnot $ Transaction idx sourcepos date edate status code description comment tags postings ""
|
||||||
return $ txnTieKnot $ Transaction i' sourcepos date edate status code description comment tags postings ""
|
|
||||||
|
|
||||||
#ifdef TESTS
|
#ifdef TESTS
|
||||||
test_transactionp = do
|
test_transactionp = do
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user