IMHO, for what you describe, i.e. "I'd like to view an atom's changes in state as a lazy sequence." there is no need to change the IAtom or add-watch function.
Watchers are called for their side-effects, so if you want to consume their output as a "lazy sequence", you have to do that transformation step in the watcher function that you attach to the atom/ref/agent. Having said that, as changes to an atom happen asynchronously, I don't think that exposing it as lazy-seq is very efficient way of consuming the values. However, with the advent of core.async, there is now a very elegant way of consuming them via a channel and that channel can have a transducer stack attached (clojure 1.7+), so something along the lines of (def atom-to-watch (atom 0)) (defn make-watcher [out-ch-with-transducer] (fn [x] (async/put! out-ch-with-transducer x)))) (def ch (async/chan 100 your-transducer-stack)) (add-watch atom-to-watch (make-watcher ch)) ;; somewhere else in your code you can consume the values (go (loop [v (async/<! ch)] ... )) Obviously you need to make sure that the values get consumed on the channel or use a dropping or sliding buffer. hope this helps, Las 2014-10-27 5:39 GMT+00:00 Mike Thompson <m.l.thompson...@gmail.com>: > > I've been reading about transducers with interest. > > The official docs at http://clojure.org/transducers say "*Because > transducers are decoupled from input or output sources, they can be used in > many different processes - collections, streams, channels, observables, > etc.* " > > At this stage, there is direct support for collections and core.async. But, > given the comment above about "observables", this got me to wondering > about another scenario ... > > I'd like to view an atom's changes in state as a lazy sequence. The first > state of the atom is like the first item in the seq, the next time the atom > changes state, its new state is the second item in the seq is generated, > etc. An infinite seq of new states. (I want to do this in the context of > clojurescript and a GUI library called reagent. Think FRP). > > Now imagine that I could attach a transducer to this seq of state changes, > so that I end up with a modified seq of state changes. > > Now, I can figure out how to do this by gluing together an atom watcher > with a core.sync channel. All doable with a small bit of work, I guess. > > But I wondered. Given the claim above about transducers and how they can > be used in the case of observables, should this atom-as-seq-with-transducer > be easier? Should the IAtom interface or the add-watcher function be > changed to make this process easier? > > Just a thought. > > -- > Mike > > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to the Google Groups > "Clojure" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/d/optout. > -- László Török Checkout justonemorepoint.com - Know your true value -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.