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 ++++++++++++++++++++-- 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 -- cgit v1.2.3