-
-
Save richhickey/311541 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defmacro gen-iter-fn | |
[name [op coll] has-item-body item-body move!-body] | |
`(defn ~name [~op ~coll] | |
(letfn | |
[(iter# [~op ~coll] | |
(reify :as ~'this | |
~'Iter | |
(~'has-item [] ~@has-item-body) | |
(~'item [] ~@item-body) | |
(~'move! [] ~@move!-body) | |
~'Transient | |
(~'value-of [] | |
(reify Editable | |
(transient-of [sentry#] | |
(iter# ~op (make-cell sentry# (sequence (deref ~coll)))))))))] | |
(iter-seq (iter# ~op (cell (sequence ~coll))))))) | |
(gen-iter-fn filterx [pred coll] | |
[(loop [cc coll] | |
(when (and (<< has-item cc) (not (pred (<< item cc)))) | |
(recur (>> move! cc)))) | |
(<< has-item coll)] | |
[(<< item coll)] | |
[(>> move! coll) this]) | |
(gen-iter-fn mapx [f coll] | |
[(<< has-item coll)] | |
[(f (<< item coll))] | |
[(>> move! coll) this]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment