diff options
-rw-r--r-- | gtwiwtg.lisp | 22 | ||||
-rw-r--r-- | package.lisp | 2 |
2 files changed, 22 insertions, 2 deletions
diff --git a/gtwiwtg.lisp b/gtwiwtg.lisp index d1b3451..8e082c3 100644 --- a/gtwiwtg.lisp +++ b/gtwiwtg.lisp @@ -483,8 +483,6 @@ Caveat: (apply #'map! #'list gen gens)) - - (defun merge! (comparator gen1 gen2 &rest gens) "Emulates the behavior of MERGE (in the ANSI standard), but for generators. @@ -528,6 +526,26 @@ Error Conditions: (lambda () (null all-gens))))) + +(defun skip! (n gen) + "Returns the generator GEN but without the first N elements. + +An error will be signalled if GEN does hot have N ore more elements." + (dotimes (x n) (next gen)) + (setf (slot-value gen 'dirty-p) nil) + gen) + +(defun skip-while! (pred gen) + "Returns the generator GEN but without the first N elements for +which PRED is non-nil. + +An error will be signalled if GEN runs out of elements before PRED +returns NIL." + (loop :while (funcall pred (next gen))) + (setf (slot-value gen 'dirty-p) nil) + gen) + + ;;; CONSUMERS (defmacro iter ((var-exp gen) &body body) diff --git a/package.lisp b/package.lisp index 964b785..5e7c452 100644 --- a/package.lisp +++ b/package.lisp @@ -22,6 +22,8 @@ #:concat! #:zip! #:merge! + #:skip! + #:skip-while! #:iter #:fold #:collect |