import Control.Monad.IO.Class (liftIO)
import Control.Monad.Trans.Except (runExceptT)
import qualified Data.Either
+import Data.Functor.Compose (Compose(..))
+import qualified Data.List
+import qualified Data.Map.Strict as Data.Map
import Data.Foldable (foldr)
import System.Console.GetOpt
( ArgDescr(..)
let transactions =
foldr
(Ledger.Journal.fold
- (flip (foldr
- (flip (foldr
- (\tr ->
- case Filter.test (ctx_transaction_filter ctx) tr of
- False -> id
- True -> (:) tr
- ))))
- . Ledger.journal_transactions))
- []
+ (\j ->
+ let ts = Ledger.journal_transactions j in
+ Data.Map.unionWith (++) $
+ case ctx_transaction_filter ctx of
+ Filter.Any -> ts
+ _ ->
+ Data.Map.mapMaybe
+ (\lt ->
+ case Data.List.filter
+ (Filter.test (ctx_transaction_filter ctx)) lt of
+ [] -> Nothing
+ l -> Just l
+ )
+ ts
+ ))
+ Data.Map.empty
journals
Ledger.Write.put sty IO.stdout $ do
- Ledger.Write.transactions transactions
+ Ledger.Write.transactions (Compose transactions)