diff options
author | Colin Okay <cbeok@protonmail.com> | 2020-07-08 16:59:57 -0500 |
---|---|---|
committer | Colin Okay <cbeok@protonmail.com> | 2020-07-08 16:59:57 -0500 |
commit | 505125f0faf8c93a2e9a39148507cd9d21b8f691 (patch) | |
tree | 89bc31efbc8bdbe8714fbad5edc53913dea188f3 | |
parent | 36ebadc03aba964446e37ae05b72d7f5e7a82389 (diff) |
added skip! and skip-while!
-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 |