aboutsummaryrefslogtreecommitdiffhomepage
path: root/gtwiwtg.lisp
diff options
context:
space:
mode:
authorColin Okay <cbeok@protonmail.com>2020-07-11 12:42:23 -0500
committerColin Okay <cbeok@protonmail.com>2020-07-11 12:42:23 -0500
commit234a192c3845069d5f26455dfcbe27edc9787fa8 (patch)
tree14040d32780ad7eb57098d0d58a00bb863af80bd /gtwiwtg.lisp
parent9882e084874c5640feeac4390431a450c9edfeec (diff)
added a few more combinators and and an example
Diffstat (limited to 'gtwiwtg.lisp')
-rw-r--r--gtwiwtg.lisp20
1 files changed, 20 insertions, 0 deletions
diff --git a/gtwiwtg.lisp b/gtwiwtg.lisp
index 3cf1871..5e954ee 100644
--- a/gtwiwtg.lisp
+++ b/gtwiwtg.lisp
@@ -629,6 +629,26 @@ Caveat:
(list (filter! pred gen1)
(filter! (complement pred) gen2))))
+(defun intersperse! (gen1 gen2 &rest gens)
+ (inflate! #'seq (apply #'zip! gen1 gen2 gens)))
+
+(defun truncate! (n gen)
+ (map! #'first (zip! gen (times n))))
+
+(defun inject! (fn gen)
+ (map! (lambda (x) (funcall fn x) x) gen))
+
+(defun disperse! (n gen)
+ (loop
+ :for i :below n
+ :for cloned :in (nfurcate! n gen)
+ :collect
+ (let ((j i))
+ (map! #'second
+ (filter! (lambda (pair) (= j (mod (first pair) n)))
+ (indexed! cloned))))))
+
+
;;; CONSUMERS
(defmacro for (var-exp gen &body body)