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

Christopher Lam clam at code.gnucash.org
Sun Jan 29 10:52:09 EST 2023


Updated	 via  https://github.com/Gnucash/gnucash/commit/34be3c8b (commit)
	from  https://github.com/Gnucash/gnucash/commit/3a6d1ea6 (commit)



commit 34be3c8b14c97fd06a2a113d2a960f2089e3a279
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Jan 29 14:25:41 2023 +0800

    [report-utilities] use fold for gnc:accounts-count-splits
    
    previous definition would build intermediate lists for each step. also
    handles the null account-list.

diff --git a/gnucash/report/report-utilities.scm b/gnucash/report/report-utilities.scm
index 36253fe31..79d3131f8 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 1016e3999..c198ec430 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)



Summary of changes:
 gnucash/report/report-utilities.scm           | 2 +-
 gnucash/report/test/test-report-utilities.scm | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)



More information about the gnucash-changes mailing list