aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorColin Okay <okay@toyful.space>2021-02-21 09:27:23 -0600
committerColin Okay <okay@toyful.space>2021-02-21 09:27:23 -0600
commitbc13f1511e1f943b89c17ce1bd5524d4c0ede34e (patch)
treec5e2700f80a8d1f49ae1343bccddc9e4b0691778
parent2180fa5972de261d8a098632e962f69a2399d1c6 (diff)
reorganizing file
-rw-r--r--gtwiwtg.lisp48
1 files changed, 26 insertions, 22 deletions
diff --git a/gtwiwtg.lisp b/gtwiwtg.lisp
index 413fce0..059c1b0 100644
--- a/gtwiwtg.lisp
+++ b/gtwiwtg.lisp
@@ -126,6 +126,32 @@
(defmethod stop :after ((g stream-backed-generator!))
(close (slot-value g 'stream)))
+
+
+(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))
+ (pop (slot-value gen 'on-deck)))
+
+(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)
+ :for candidate = (next source-generator)
+ :when (funcall predicate candidate)
+ :do (push candidate on-deck)
+ (return t)
+ :finally (return nil)))))
+
+(defmethod stop :after ((gen filtered-generator))
+ (stop (slot-value gen 'source-generator)))
+
+
;;; CONSTRUCTORS
(defun range (&key (from 0) to (by 1) inclusive)
@@ -363,28 +389,6 @@ Error Conditions:
(lambda ()
(dolist (g all-gens) (stop g))))))
-(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))
- (pop (slot-value gen 'on-deck)))
-
-(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)
- :for candidate = (next source-generator)
- :when (funcall predicate candidate)
- :do (push candidate on-deck)
- (return t)
- :finally (return nil)))))
-
-(defmethod stop :after ((gen filtered-generator))
- (stop (slot-value gen 'source-generator)))
(defun filter! (pred gen)