Skip to content

Instantly share code, notes, and snippets.

@rauhs
Created August 15, 2015 15:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rauhs/01d98084d9d2b9c9fd81 to your computer and use it in GitHub Desktop.
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)
(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
@rauhs
Copy link
Author

rauhs commented Aug 22, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment