chore: adjust and fix DEDUPING and COMPRESSING-RUNS

This commit is contained in:
Edward
2021-01-04 00:49:39 -08:00
parent 5bca9a117f
commit 705dc56244

View File

@ -67,20 +67,8 @@
(filtering (lambda (it) (filtering (lambda (it)
(nth-value 1 (apply function it args))))) (nth-value 1 (apply function it args)))))
(defun deduping (&optional (test 'eql))
(lambda (rf)
(let (last)
(transducer-lambda
((acc next)
(prog1 (if (or (null last)
(funcall test last next))
acc
(funcall rf acc next))
(setf last next)))
((it) (funcall rf it))))))
(defun seq (a b) a b) (defun seq (a b) a b)
(defun compressing-runs (&optional (test 'eql) (combiner 'seq)) (defun compressing-runs (&key (test 'eql) (combiner 'seq))
(lambda (rf) (lambda (rf)
(let (last leftovers) (let (last leftovers)
(transducer-lambda (transducer-lambda
@ -91,7 +79,7 @@
leftovers t) leftovers t)
acc) acc)
(progn (prog1 (funcall rf acc last) (progn (prog1 (funcall rf acc last)
(setf last next))))) (setf last (funcall combiner last next))))))
((it) ((it)
(funcall rf (funcall rf
(if leftovers (if leftovers
@ -99,11 +87,14 @@
it))))))) it)))))))
(defun deduping (&optional (test 'eql))
(compressing-runs :test test))
(defun catting () (defun catting ()
(lambda (rf) (lambda (rf)
(transducer-lambda (transducer-lambda
((acc next) ((acc next)
(reduce rf next :initial-value acc)) (reduce-generic next rf acc))
((it) (funcall rf it))))) ((it) (funcall rf it)))))
(defun mapcatting (fun) (defun mapcatting (fun)