Touching the accumulator (the result in your case) from within a transducing function is a bit of an anti-pattern. The whole point of transducers is that you can swap out the accumulator:
(transduce (map inc) conj [] (range 10)) (transduce (map inc) async/>! some-channel (range 10)) (transduce (map inc) + 0 (range 10)) In this example, we loose that ability to swap out the result type if `(map inc)` assumes that the accumulator will always be a vector, or a integer. This is why I said map/filter/keep should handle most of your cases. If the function you are writing doesn't require the accumulator to function properly, then there is no reason why `(map my-fn)` won't work. On Sat, Jun 11, 2016 at 12:13 AM, Travis Daudelin <[email protected] > wrote: > On Friday, June 10, 2016 at 3:03:38 PM UTC-7, Francis Avila wrote: >> >> A higher-order function can do what this macro does: >> https://gist.github.com/favila/ecdd031e22426b93a78f >> > > Oh nice! It looks like I came up with an almost identical solution: > (defn transducing > [f] > (fn [reducing-fn] > (fn > ([] (reducing-fn)) > ([result] (reducing-fn result)) > ([result input] (f result input reducing-fn))))) > > It feels like "writing a custom transducer" should be a common use case, > is there anything like these functions we've written that exists in the > core library? I didn't see anything like them there or in the reducers > library when I first started on my project. > > -- > 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. > -- “One of the main causes of the fall of the Roman Empire was that–lacking zero–they had no way to indicate successful termination of their C programs.” (Robert Firth) -- 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.
