Even though evaluation and realization of sequences is lazy, they cache 
their result after evaluation. If you consume an object from the `sequence` 
function more than once, the work is only done once. Sequences are iterable 
and reducible, but not as efficiently because of the caching and because 
internally they have a linked-list structure (pointers rather than arrays).

`sequence` produces pretty much the same thing as "normal" lazy-sequence 
clojure. `(sequence (map f) xs)` and `(map f x)` are equivalent.

`eduction` produces an object that does not cache the result of transducer 
transformations. It's iteration and reduction implementations are faster, 
but the result is not cached.

Your error is because cheshire does not know how to serialize an Eduction 
object to Json.

On Friday, December 22, 2017 at 8:32:54 AM UTC-6, Jonathon McKitrick wrote:
>
> I have a `get-summary` function that builds stats and returns them as a 
> web service. Under the hood, it calls quite a few map, group-by, filter, 
> etc. functions.
>
> I’m experimenting with transducers, and `sequence xform` does the trick 
> most of the time. But I want to understand `eduction` use cases. In most 
> cases, `eduction` seems to be a drop-in replacement. But in a few cases, 
> I’m seeing this error:
>
> JsonGenerationException Cannot JSON encode object of class: class 
> clojure.core.Eduction: clojure.core.Eduction@31accd87 
>  cheshire.generate/generate (generate.clj:152)
>
> So there’s something I’m missing about my understanding of `sequence` 
> versus `eduction`. Can someone shine some light on it?
>
> Thanks!
>

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