Created
August 15, 2015 15:53
-
-
Save rauhs/01d98084d9d2b9c9fd81 to your computer and use it in GitHub Desktop.
Changing your transducer during the runtime of your core.async channel (could use some optimizaiton caching the instantiation)
This file contains hidden or 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
(def xf-a | |
(atom (map inc))) | |
(defn xf [& args-out] | |
(fn [& args] | |
;; TODO: Cache the inner (apply...) | |
(apply (apply @xf-a args-out) args))) | |
(def ch (chan 1 xf)) | |
(>!! ch 1) | |
(pr (<!! ch));; => 2 | |
(reset! xf-a (map dec)) | |
(>!! ch 1) | |
(pr (<!! ch));; => 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: Doesn't properly drain a transducer when the channel closes. Doesnt' work really with stateful transducers. Use with simple
map
/filter
and not much more.