On Wed, Apr 1, 2015 at 3:17 PM, Tassilo Horn <t...@gnu.org> wrote: > Alex Miller <a...@puredanger.com> 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 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. > > > > Yes, that's what I guessed. But at least when I tested replacing > > sequence with eduction at exactly these places () the result has > > been a slight slowdown instead of a speedup. But that might have > > been accidental as it is hard to do measurements with real-world > > code where a 5% slowdown/speedup might be the reason of something > > completely unrelated. > > > > Are you including the cost of realizing the elements? > > Oh, yes, and not only that. The tests I did maybe spend 20% of their > time in the transducer part, 80% in other stuff. So I definitively have > to do some more elaborate benchmarking where the transducer part is > somehow isolated. > > That's why I've asked if there are clear usage-recipes when to use what. > I think my prime use-case is deeply nested mapcatting where the > mapcatted function gets an object and returns a java collection, and > filtering with usually a quite cheap predicate. E.g. > > (sequence-or-eduction (comp (mapcat ...) > (filter ...) > (mapcat ...) > ... > (filter ...)) > coll) > > That's part of a larger search algorithm which either stops after > finding the first match (in which case the resulting sequence is likely > not to be realized completely) or runs till all matches are found (in > which case all these transducer-produced sequences would be fully > realized). > > If that would make sense, I could use eduction when I know everything > will be realized and sequence in the other case (or vice versa). > In this case, I don't know that I'd expect much difference. sequence is going to create a TransformerIterator, and wrap it in an chunkedIteratorSeq. Using (seq (eduction ...) should give you exactly the same thing, except calling through an Eduction type. So, I doubt it matters. > Bye, > Tassilo > -- 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.