snakes
Python style generators for Common Lisp. Includes a port of itertools.

Examples:

(defgenerator some-numbers () (loop for i from 1 upto 3 do (yield i)) (print 'some-message) (loop for i from 8 upto 9 do (yield i))) ;; => SOME-NUMBERS (do-generator (item (some-numbers)) (when (< 3 item) (return item))) ;; => SOME-MESSAGE 8

Pipe-able generator:

(defgenerator add2 (some-gen) (do-generator (x some-gen) (yield (+ 2 x)))) ;; => ADD2 (generator->list (add2 (some-numbers))) ;; => SOME-MESSAGE (3 4 5 10 11)

Yield-all:

(defgenerator flatten (list) (when list (cond ((atom list) (yield list)) (t (yield-all (flatten (car list))) (yield-all (flatten (cdr list))))))) ;; => FLATTEN (mapc-generator #'print (flatten '((a (b c) d) (e) f (g h)))) ;; => A B C D E F G H

Homepage: GitHub

License: Apache 2.0

See Also: cl-itertools, pygen

Topics: language extension