[report-utilities] use fold for gnc:accounts-count-splits

previous definition would build intermediate lists for each step. also
handles the null account-list.
This commit is contained in:
Christopher Lam 2023-01-29 14:25:41 +08:00
parent 3a6d1ea663
commit 34be3c8b14
2 changed files with 5 additions and 1 deletions

View File

@ -741,7 +741,7 @@ query instead.")
;; function to count the total number of splits to be iterated
(define (gnc:accounts-count-splits accounts)
(apply + (map length (map xaccAccountGetSplitList accounts))))
(fold (lambda (a b) (+ b (length (xaccAccountGetSplitList a)))) 0 accounts))
;; Sums up any splits of a certain type affecting a set of accounts.
;; the type is an alist '((str "match me") (cased #f) (regexp #f))

View File

@ -477,6 +477,10 @@
44
(gnc:accounts-count-splits (list expense income)))
(test-equal "gnc:accounts-count-splits null"
0
(gnc:accounts-count-splits '()))
(let ((account-balances (gnc:get-assoc-account-balances
(list bank gbp-bank)
(lambda (acct)