diff options
author | Colin Okay <okay@toyful.space> | 2021-02-21 09:31:34 -0600 |
---|---|---|
committer | Colin Okay <okay@toyful.space> | 2021-02-21 09:31:34 -0600 |
commit | 6e7805d241360a5e1185dd41c6099f7f5aae5dba (patch) | |
tree | ce4af4331e9761e0050999ea30cd8d0e8795b0c9 | |
parent | bc13f1511e1f943b89c17ce1bd5524d4c0ede34e (diff) |
redef of filtered generator to use a-generator-class macro
-rw-r--r-- | gtwiwtg.lisp | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/gtwiwtg.lisp b/gtwiwtg.lisp index 059c1b0..5394224 100644 --- a/gtwiwtg.lisp +++ b/gtwiwtg.lisp @@ -126,19 +126,15 @@ (defmethod stop :after ((g stream-backed-generator!)) (close (slot-value g 'stream))) +(a-generator-class filtered-generator! () + (on-deck (list)) + (source-generator (error "filtered generator must have a source")) + (predicate (error "filtered generator must have a predicate"))) - -(defclass filtered-generator (generator!) - ((on-deck :initform (list)) - (source-generator :initform (error "filtered generator must have a source") - :initarg :source) - (predicate :initform (error "filtered generator must have a predicate") - :initarg :predicate))) - -(defmethod next ((gen filtered-generator)) +(defmethod next ((gen filtered-generator!)) (pop (slot-value gen 'on-deck))) -(defmethod has-next-p ((gen filtered-generator)) +(defmethod has-next-p ((gen filtered-generator!)) (with-slots (source-generator predicate on-deck) gen (or on-deck (loop :while (has-next-p source-generator) @@ -148,7 +144,7 @@ (return t) :finally (return nil))))) -(defmethod stop :after ((gen filtered-generator)) +(defmethod stop :after ((gen filtered-generator!)) (stop (slot-value gen 'source-generator))) @@ -398,7 +394,7 @@ Error Condition: - If GEN has been used elsewhere, an error will be signalled. " (sully-when-clean (list gen)) - (make-instance 'filtered-generator :predicate pred :source gen)) + (make-instance 'filtered-generator! :predicate pred :source-generator gen)) (defun inflate! (fn gen &key extra-cleanup) |