Thanks Bobby! And apologies for being too lazy to search for these threads.
On Thursday, 1 September 2016, Bobby Eickhoff <[email protected]> wrote: > 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 [email protected] > <javascript:_e(%7B%7D,'cvml','[email protected]');> > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > [email protected] > <javascript:_e(%7B%7D,'cvml','clojure%[email protected]');> > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en > --- > You received this message because you are subscribed to a topic in the > Google Groups "Clojure" group. > To unsubscribe from this topic, visit https://groups.google.com/d/ > topic/clojure/2VBF11AHe58/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > [email protected] > <javascript:_e(%7B%7D,'cvml','clojure%[email protected]');>. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to [email protected] 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 [email protected]. For more options, visit https://groups.google.com/d/optout.
