On Jan 21, 7:40 pm, Vincent Foley <vfo...@gmail.com> wrote:
> I have a question regarding the examples, specifically map* and
> filter*
>
> (defn map* [f coll]
> (let [iter (stream-iter coll)]
> (stream
> (fn [eos]
> (let [x (next! iter eos)]
> (if (= eos x) x (f x)))))))
>
> (take 4 (map* inc (filter* even? (range 1000000))))
> -> (1 3 5 7)
>
> How is eos passed to the fn inside stream and what is it?
>
The caller provides eos in calls to the (next! iter eos), which in
turn passes it to the generator. The caller should choose a value for
eos that will not be present in the set of items, which can easily be
created by calling (Object.), as is done by reduce*.
I've enhanced the docs to explain this, and commented the example.
Rich
--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---