Fix example a bit

This commit is contained in:
Ed Langley
2018-08-18 13:06:28 -07:00
parent 289289e708
commit 48ff3c1166
2 changed files with 20 additions and 16 deletions

View File

@ -6,16 +6,17 @@ the composition of more primitive operations.
#+BEGIN_SRC lisp #+BEGIN_SRC lisp
DATA-LENS> (funcall (on (compress-runs :collector 'combine-matching-lists) DATA-LENS> (funcall (on (compress-runs :collector 'combine-matching-lists)
(alexandria:compose (alexandria:compose
(over (juxt (element 0) (over (data-lens:juxt
(data-lens:element 0)
'identity)) 'identity))
(sorted 'string<))) (sorted 'char< :key (element 0))))
'("January" "February" "March" "April" '("January" "February" "March" "April"
"May" "June" "July" "August" "May" "June" "July" "August"
"September" "October" "November" "December")) "September" "October" "November" "December"))
#| ==> ((#\A "April" "August") #| ==> ((#\A "April" "August")
(#\D "December") (#\D "December")
(#\F "February") (#\F "February")
(#\J "January" "July" "June") (#\J "January" "June" "July")
(#\M "March" "May") (#\M "March" "May")
(#\N "November") (#\N "November")
(#\O "October") (#\O "October")

View File

@ -52,15 +52,18 @@
acc acc
(cons next acc)))) (cons next acc))))
(defun combine-matching-lists (&key (test 'eql) &allow-other-keys) (defun matching-list-reducer (test acc next)
(lambda (acc next)
(if (and acc (if (and acc
(funcall test (caar acc) (car next))) (funcall test (caar acc) (car next)))
(cons (cons (caar acc) (cons (cons (caar acc)
(append (cdar acc) (append (cdar acc)
(cdr next))) (cdr next)))
(cdr acc)) (cdr acc))
(cons next acc)))) (cons next acc)))
(defun combine-matching-lists (&key (test 'eql) &allow-other-keys)
(lambda (acc next)
(matching-list-reducer test acc next)))
(defun-ct compress-runs (&key (collector 'cons-new) (test 'eql) (key 'identity)) (defun-ct compress-runs (&key (collector 'cons-new) (test 'eql) (key 'identity))
(lambda (it) (lambda (it)
@ -72,7 +75,7 @@
(defun-ct sorted (comparator &rest r &key key) (defun-ct sorted (comparator &rest r &key key)
(declare (ignore key)) (declare (ignore key))
(lambda (it) (lambda (it)
(apply #'sort (copy-seq it) comparator r))) (apply #'stable-sort (copy-seq it) comparator r)))
(defun-ct element (num) (defun-ct element (num)
(lambda (it) (lambda (it)