From 505125f0faf8c93a2e9a39148507cd9d21b8f691 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Wed, 8 Jul 2020 16:59:57 -0500 Subject: added skip! and skip-while! --- gtwiwtg.lisp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'gtwiwtg.lisp') 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) -- cgit v1.2.3