aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorOscar Najera <hi@oscarnajera.com>2023-04-23 18:47:08 +0200
committerOscar Najera <hi@oscarnajera.com>2023-04-23 19:28:46 +0200
commit56bd7782cd5ce62baad0d15d7eaa2333e1ca56e0 (patch)
treedb4758af584efa731d9e3fe4c584d5d9737b0c49 /lib
parent34103c087aeb885bf351b0c387dbbf08ae4327a5 (diff)
downloaddotfiles-56bd7782cd5ce62baad0d15d7eaa2333e1ca56e0.tar.gz
dotfiles-56bd7782cd5ce62baad0d15d7eaa2333e1ca56e0.tar.bz2
dotfiles-56bd7782cd5ce62baad0d15d7eaa2333e1ca56e0.zip
Loop lines on read-habit
Diffstat (limited to 'lib')
-rwxr-xr-xlib/guile/read-habit.scm37
1 files changed, 21 insertions, 16 deletions
diff --git a/lib/guile/read-habit.scm b/lib/guile/read-habit.scm
index 7ba7002..b3c7888 100755
--- a/lib/guile/read-habit.scm
+++ b/lib/guile/read-habit.scm
@@ -18,21 +18,25 @@
(define habits-dir (expand-file "~/org/habits/"))
-(define (parse-file port)
- (let loop ((values '())
- (line (read-line port)))
- (if (eof-object? line)
- (reverse values)
- (loop (cons (map string->number (string-split line #\:)) values)
- (read-line port)))))
+(define (iter-lines filename proc)
+ (call-with-input-file filename
+ (lambda (port)
+ (let loop ((values '())
+ (line (read-line port)))
+ (if (eof-object? line)
+ (reverse values)
+ (loop (cons (proc line) values)
+ (read-line port)))))))
(define (cli-print file-name)
- (map (lambda (row)
- (format #t "~a -> ~d~%"
- (colorize-string (strftime "%c" (localtime (car row))) 'CYAN 'BOLD)
- (cadr row)))
- (call-with-input-file (string-append habits-dir file-name)
- parse-file)))
+ (iter-lines
+ (string-append habits-dir file-name)
+ (lambda (line)
+ (let ((row (map string->number (string-split line #\:))))
+ (format #t "~a -> ~d~%"
+ (colorize-string (strftime "%c" (localtime (car row))) 'CYAN 'BOLD)
+ (cadr row))
+ row))))
(define (request-path-components request)
(split-and-decode-uri-path (uri-path (request-uri request))))
@@ -53,9 +57,10 @@
((file-exists? (string-append habits-dir (car path)))
(values '((content-type . (application/json)))
(scm->json-string (list->vector
- (map (lambda (row) (list->vector row))
- (call-with-input-file (string-append habits-dir (car path))
- parse-file))))))
+ (iter-lines
+ (string-append habits-dir (car path))
+ (lambda (line)
+ (list->vector (map string->number (string-split line #\:)))))))))
((string=? "hi" (car path))
(values '((content-type . (application/json)))
'(hi)))