Mathias, I've never found a satisfactory answer to this question. It has been asked before.
https://groups.google.com/d/msg/clojure/HK9LkmlRyjY/S0U1u2nQCQAJ https://groups.google.com/d/msg/clojure/uVKP4_0KMwQ/-oUJahvUarIJ Hoping someone with more insight will comment on this situation. Bobby On Wednesday, August 24, 2016 at 4:00:41 AM UTC-4, Mathias De Wachter wrote: > > Hi, > > I'm trying to use the transducer framework for some sequence processing > where I have a core reduction function, but depending on options, extra > functionality can be added to the reduction function. I thought that's a > good fit for hand-written transducers. > > However, I'm running into a problem initializing the optional > functionality. I thought I would simply perform it in the 0-arity, like > this: > > (defn my-tx > [rf] > (fn > ([] (assoc (rf) ::my-ns/my-extra-field my-init-value) > ... > > But that's never called, at least not in transduce: > > (defn transduce > "..." {:added "1.7"} > ([xform f coll] (transduce xform f *(f)* coll)) > ([xform f init coll] > (let [f (xform f) > ret (if (instance? clojure.lang.IReduceInit coll) > (.reduce ^clojure.lang.IReduceInit coll f init) > (clojure.core.protocols/coll-reduce coll f init))] > (f ret)))) > > So, my question is: why the (f) instead of (xform f)? And what's the use > of the 0-arity in transducers if it's not called? I assume it's used in > other uses of transducers? > > By the way, I understand it's tricky to call (xform f) instead, because > then what do you do with a provided init... And I also understand that I > can create initial state in the closure of the transducer, so I'm not > blocked at all. I'm just very curious :). > > Thanks, > -Mathias > -- 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.