From ec51a0c9193242f7397e8dd633aaf55998c361cd Mon Sep 17 00:00:00 2001 From: Ray Miller Date: Sat, 13 Jul 2024 17:14:16 +0100 Subject: [PATCH] Simplify the update-data function. --- guile/fix-nationwide-statement.scm | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/guile/fix-nationwide-statement.scm b/guile/fix-nationwide-statement.scm index b3b9b83..c410a3c 100755 --- a/guile/fix-nationwide-statement.scm +++ b/guile/fix-nationwide-statement.scm @@ -81,15 +81,13 @@ ;; Apply the specified updates to data (a list of rows ;; read from the CSV). If a 'skip value is specified, drop ;; this many leading rows. If a 'header is present, only -;; apply the updates to the succeeding rows. +;; apply the updates to the succeeding rows, preserving +;; the header as-is. (define (update-data spec data) - (let* ((data (drop data (or (assq-ref spec 'skip) 0))) - (header (if (assq-ref spec 'header) (car data) #f)) - (data (if header (cdr data) data))) - (for-each (process-row spec) data) - (if header - (cons header data) - data))) + (let* ((skip (assq-ref spec 'skip)) + (data (if skip (drop data skip) data))) + (for-each (process-row spec) (if (assq-ref spec 'header) (cdr data) data)) + data)) ;; Apply the updates defined in `spec` to the statement read ;; from input-path and write the updated data to output-path.