Re: Having trouble doing what I want using macros, is there a better way?

2016-06-11 Thread Francis Avila
These functions (as-transducer, transducing) are still completely agnostic about the type of the accumulator and result as long as the function you give them only touches result in the following ways: 1. Return result unchanged 2. Return (xf (xf result X) Y), I.e. Whatever you get from

Re: Having trouble doing what I want using macros, is there a better way?

2016-06-11 Thread Timothy Baldridge
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

Re: Having trouble doing what I want using macros, is there a better way?

2016-06-10 Thread Travis Daudelin
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]

Re: Having trouble doing what I want using macros, is there a better way?

2016-06-10 Thread Francis Avila
A higher-order function can do what this macro does: https://gist.github.com/favila/ecdd031e22426b93a78f On Friday, June 10, 2016 at 1:07:58 PM UTC-5, Travis Daudelin wrote: > > Hi all! > > I'm current working on a project where I am ingesting events off a stream > and processing them. There

Re: Having trouble doing what I want using macros, is there a better way?

2016-06-10 Thread Travis Daudelin
Actually, I spoke too soon. It looks like completing takes in a reducing function and wraps it so that it meets the arity expectations of a transducer. While this is still super useful to my needs (thanks again!) I wanted to clarify for posterity that completing does not solve the issue in my

Re: Having trouble doing what I want using macros, is there a better way?

2016-06-10 Thread Travis Daudelin
On Friday, June 10, 2016 at 11:43:04 AM UTC-7, Bobby Eickhoff wrote: > > But maybe the core function completing is very close to what you're > looking for... > Hmm, looking through its source I'd say it's exactly what I'm looking for. Thank you! -- You received this message because you are

Re: Having trouble doing what I want using macros, is there a better way?

2016-06-10 Thread Travis Daudelin
> > I think you can do what you want with existing transducers. Won't > map/filter/keep/etc do the trick? > I can't say for sure that it's not possible, but I certainly lack the imagination :). The logic I need to write is quite complicated and I'm finding it's easier to write my own

Re: Having trouble doing what I want using macros, is there a better way?

2016-06-10 Thread Bobby Eickhoff
Having spent quite a bit of time recently dissecting transducers , I'd tend to agree with Tim: core transducers will probably give you most of what you want. I'd also agree that writing macros should be your last

Re: Having trouble doing what I want using macros, is there a better way?

2016-06-10 Thread Nate Young
You can "capture" symbols from the surrounding context, making them available to the body of your macros, the "tilde tick trick" is what you're looking for there: (defmacro deftransducer [body] `(fn [reducing-fn#] (fn ([] (reducing-fn#))

Re: Having trouble doing what I want using macros, is there a better way?

2016-06-10 Thread Raoul Duke
My $0.02 is only resort to macros when all else has failed. Can just higher order functions and composition and injection get you closer to what you want? -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to

Re: Having trouble doing what I want using macros, is there a better way?

2016-06-10 Thread Timothy Baldridge
I think you can do what you want with existing transducers. Won't map/filter/keep/etc do the trick? On Fri, Jun 10, 2016 at 7:06 PM, Travis Daudelin wrote: > Hi all! > > I'm current working on a project where I am ingesting events off a stream > and processing them.

Having trouble doing what I want using macros, is there a better way?

2016-06-10 Thread Travis Daudelin
Hi all! I'm current working on a project where I am ingesting events off a stream and processing them. There are many many steps involved in the processing component, so I am choosing to write the steps as a series of transducers (because, hey, they're super cool!). Here's the problem though,