Alex Miller <a...@puredanger.com> 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 (map inc) (range 10)))
>     (1 2 3 4 5 6 7 8 9 10)
>
> Yep. :)
>
> user=> (supers (class (eduction (map inc) (range 10))))
> #{clojure.lang.Sequential java.lang.Object java.lang.Iterable
> clojure.lang.IReduceInit clojure.lang.IType}
>
> However, seq checks for Iterable and will automatically use
> iterator-seq to produce a seq from an Iterable, which is what's
> happening here.

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. :-)

>     > 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).

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.

Reply via email to