refactor(transducers): simplify list builder

This commit is contained in:
fiddlerwoaroof
2020-12-19 19:34:20 -08:00
parent 5bd17dc8e5
commit a7399b43c6

View File

@ -127,22 +127,19 @@
(defmethod init ((it (eql 'list-builder)))
(declare (optimize (speed 3)))
(coerce (vector nil nil)
'(simple-array list (2))))
(let ((it (list nil)))
(coerce (vector it it)
'(simple-array list (2)))))
(defmethod stepper ((it (eql 'list-builder)))
(lambda (acc a)
(declare (optimize (speed 3))
(type (simple-array list (2)) acc))
(if (elt acc 1)
(let* ((to-build (elt acc 1)))
(push a (cdr to-build))
(setf (elt acc 1) (cdr to-build)))
(let ((new (list a)))
(setf (elt acc 0) new
(elt acc 1) new)))
acc))
(defmethod unwrap ((it (eql 'list-builder)) obj)
(elt obj 0))
(cdr (elt obj 0)))
(defclass lazy-sequence ()
((%next :initarg :next :reader next)))