simplified tokenize

main
Inga 🏳‍🌈 12 months ago
parent b0a3de96b4
commit 6fcf46ec3f
  1. 9
      day01-hard/main.scm

@ -55,7 +55,7 @@
(assert-eq "flat test 1 failed" (assert-eq "flat test 1 failed"
'(1 2 3 4 5 (6 7) 8) '(1 2 3 4 5 (6 7) 8)
(flat '((1 2) (3 4) (5 (6 7) 8)))) (flat '((1 2) () (3 4) (5 (6 7) 8))))
(define (filter predicate) (reduce-right '() (define (filter predicate) (reduce-right '()
(lambda (current accumulator) (lambda (current accumulator)
@ -129,12 +129,9 @@
((compose (list ((compose (list
(coalesce-not-empty (lambda () (f (cdr values)))) (coalesce-not-empty (lambda () (f (cdr values))))
flat flat
(filter id) (map (lambda (token) ((compose (list
(map
(lambda (token)
((truthy-chaining (compose (list
(map (prepend (car token))) (map (prepend (car token)))
(lambda (rest) (f (next rest values)))))) (lambda (rest) (if rest (f (next rest values)) '()))))
(starts-with (cdr token) values)))))) (starts-with (cdr token) values))))))
tokens)))))) tokens))))))

Loading…
Cancel
Save