stream.el
;; 模仿 ls -R
(defun foo ()
(interactive)
(with-current-buffer (get-buffer-create "*LS*")
(setq buffer-undo-list t)
(erase-buffer)
(switch-to-buffer (current-buffer))
(seq-do
(lambda (f)
(insert f ?\n)
(goto-char (point-max))
(set-window-point (selected-window) (point-max))
(redisplay))
(stream-of-directory-files "~/.emacs.d/" nil 'nosort 'recurse))))
iter-defun is defined in generator.el
(iter-defun fibonacci ()
(let ((a 0)
(b 1))
(while t
(iter-yield a)
(cl-psetq a b
b (+ a b)))))
;; 前 10 个斐波那契数
(cl-loop repeat 10
for n iter-by (fibonacci)
collect n)
(-> (fibonacci)
(stream-from-iterator)
(seq-take 10)
(seq-into 'list))
(defun fib (a b)
(stream-cons a (fib b (+ a b))))
(seq-into (seq-take (fib 0 1) 10) 'list)
(seq-into (stream-range 0 5) 'list)
(seq-into (seq-take (stream-range 0) 5) 'list)
(seq-into
(seq-take (stream-scan #'* 1 (stream-range 1)) 5)
'list)
(map-let (x y) '((x . 1) (y . 2))
(list :x x
:y y))
(map-let (x y) '((x . 1) (y . 2))
(list :x x
:y y))
(map-let (('x a) ('y b)) '((x . 1) (y . 2))
(list a b))