From 34be3c8b14c97fd06a2a113d2a960f2089e3a279 Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Sun, 29 Jan 2023 14:25:41 +0800 Subject: [PATCH] [report-utilities] use fold for gnc:accounts-count-splits previous definition would build intermediate lists for each step. also handles the null account-list. --- gnucash/report/report-utilities.scm | 2 +- gnucash/report/test/test-report-utilities.scm | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/gnucash/report/report-utilities.scm b/gnucash/report/report-utilities.scm index 36253fe31f..79d3131f89 100644 --- a/gnucash/report/report-utilities.scm +++ b/gnucash/report/report-utilities.scm @@ -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)) diff --git a/gnucash/report/test/test-report-utilities.scm b/gnucash/report/test/test-report-utilities.scm index 1016e3999d..c198ec430e 100644 --- a/gnucash/report/test/test-report-utilities.scm +++ b/gnucash/report/test/test-report-utilities.scm @@ -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)