Re: Transducers: sequence versus eduction

2015-04-03 Thread Alex Miller
I understand your point and there are several competing comparisons here. Generally only collection functions take the coll first. eduction is similar to sequence (and into and reduce and transduce) in taking it last (but differs in taking multiple xforms). The multiple xforms are similar to ->

Re: Transducers: sequence versus eduction

2015-04-03 Thread Steve Miner
> On Apr 1, 2015, at 11:16 AM, Alex Miller wrote: > > - eduction now takes multiple transformations, not just one, and composes > them. This is designed for mechanical rewriting (hello tool developers!!) of > ->> chains like this: > > (->> s (interpose 5) (partition-all 2)) > > to this: > >

Re: Transducers: sequence versus eduction

2015-04-02 Thread Tassilo Horn
Alex Miller writes: Hi Alex, > Just for fun, I ran the (dorun (sequence (comp (mapcat #(range %)) > (mapcat # (range %))) (range 1000))) and eduction version with the > CLJ-1515 patch. I saw ~ 20 seconds before and 15 seconds after. > > But the new version also makes pure seqs better and I saw t

Re: Transducers: sequence versus eduction

2015-04-02 Thread Alex Miller
Just for fun, I ran the (dorun (sequence (comp (mapcat #(range %)) (mapcat #(range %))) (range 1000))) and eduction version with the CLJ-1515 patch. I saw ~20 seconds before and 15 seconds after. But the new version also makes pure seqs better and I saw the full (dorun ...) drop from 6 seconds

Re: Transducers: sequence versus eduction

2015-04-02 Thread MichaƂ Marczyk
It may be worth noting that while the return value of range is wrapped in lazy-seq and thus isn't itself a clojure.lang.IChunkedSeq, what you get when you realize it is indeed chunked: (contains? (ancestors (class (seq (range 128 clojure.lang.IChunkedSeq) true It doesn't implement c.l.IReduce

Re: Transducers: sequence versus eduction

2015-04-02 Thread Tassilo Horn
Alex Miller writes: Hi Alex, > If you're going to use expanding transformations and not realize all of the > results then I think sequences are likely a better choice for you. Ok, I see. >> However, at least I had expected that in the case where all elements >> are realized the transducer vers

Re: Transducers: sequence versus eduction

2015-04-02 Thread Alex Miller
> On Apr 2, 2015, at 4:09 AM, Tassilo Horn wrote: > So we can agree on eduction not being a Sequable but still being > sequable. :-) Agreed. :) > >>I think my prime use-case is deeply nested mapcatting where the >>mapcatted function gets an object and returns a java collection, and

Re: Transducers: sequence versus eduction

2015-04-02 Thread Tassilo Horn
Alex Miller writes: > Ok. But to me, if I can call `seq` on a thing and iterate it using > `first` and `rest`, that's a sequable thing to me. :-) > > Fair enough. I just meant it no longer implements Seqable. :) Yes, I got that. But I think that's an implementation detail. I go with t

Re: Transducers: sequence versus eduction

2015-04-01 Thread Alex Miller
On Wed, Apr 1, 2015 at 3:17 PM, Tassilo Horn wrote: > Alex Miller writes: > > Ok. But to me, if I can call `seq` on a thing and iterate it using > `first` and `rest`, that's a sequable thing to me. :-) > Fair enough. I just meant it no longer implements Seqable. :) > > > The general idea

Re: Transducers: sequence versus eduction

2015-04-01 Thread Tassilo Horn
Alex Miller writes: > > seqable (but it is reducible and iterable). You can use > > iterator-seq to get a chunked seq over the top if you need one. > > Really? > > user> *clojure-version* > {:major 1, :minor 7, :incremental 0, :qualifier "alpha6"} > user> (seq (eduction (m

Re: Transducers: sequence versus eduction

2015-04-01 Thread Alex Miller
On Wed, Apr 1, 2015 at 2:17 PM, Tassilo Horn wrote: > Alex Miller writes: > > Hi Alex, > > > - Eduction is no longer Seqable and thus the return from eduction is not > > seqable (but it is reducible and iterable). You can use iterator-seq to > get a > > chunked seq over the top if you need one.

Re: Transducers: sequence versus eduction

2015-04-01 Thread Tassilo Horn
Alex Miller writes: Hi Alex, > - Eduction is no longer Seqable and thus the return from eduction is not > seqable (but it is reducible and iterable). You can use iterator-seq to get a > chunked seq over the top if you need one. Really? user> *clojure-version* {:major 1, :minor 7, :incremental

Re: Transducers: sequence versus eduction

2015-04-01 Thread Alex Miller
The general idea is that eduction is best when the result will be completely consumed in a reducible context. Any case of reusing the result will likely be better served by sequence which can cache and reuse the answer. On Wednesday, April 1, 2015 at 3:51:53 AM UTC-5, Tassilo Horn wrote: > > vv

Re: Transducers: sequence versus eduction

2015-04-01 Thread Alex Miller
First, I love this discussion! Great questions, great thinking. Up top, I wanted to mention a couple things that have changed in alpha6: - Eduction is no longer Seqable and thus the return from eduction is not seqable (but it is reducible and iterable). You can use iterator-seq to get a chunked

Re: Transducers: sequence versus eduction

2015-04-01 Thread Tassilo Horn
vve...@gmail.com writes: > Eduction retains the ability to be recomposed with other transducers > higher in the function chain. The following two are nearly equivalent: > > (transduce (take 1e2) + (eduction (filter odd?) (range))) > (transduce (comp (filter odd?) (take 1e2)) + (range)) > > This wi

Re: Transducers: sequence versus eduction

2015-04-01 Thread vvedee
Eduction retains the ability to be recomposed with other transducers higher in the function chain. The following two are nearly equivalent: (transduce (take 1e2) + (eduction (filter odd?) (range))) (transduce (comp (filter odd?) (take 1e2)) + (range)) This will be slower: (transduce (take 1e2) +

Transducers: sequence versus eduction

2015-04-01 Thread Tassilo Horn
Hi all, I've switched many nested filter/map/mapcat applications in my code to using transducers. That brought a moderate speedup in certain cases and the deeper the nesting has been before, the clearer the transducers code is in comparison, so yay! :-) However, I'm still quite unsure about the