On Wednesday, May 2, 2012 7:24:04 AM UTC+3, Sean Neilan wrote:
>
> Hi,
>
> I'm sure this has been discussed to death but I can't figure it out. 
>
> I've got a file-seq sequence from
> (file-seq (java.io.File. "/DirectoryWithMillionsOfFiles/")) that will 
> cause an out of memory error if realized.
>
> I want to call a function such as println on every element in the sequence.
>
> I understand that naming the sequence will cause it to be realized.
>
> The problems
>
>    1. I can't use map as in (map println (file-seq (java.io.File. 
>    "/DirectoryWithMillionsOfFiles"))). Map realizes the sequence.
>    2. I can't use for as in (for [x (files)] (println x)). For realizes 
>    the sequence.
>
> Try doseq instead:

    (doseq [x (files)]
      (println x))
 

>
>    1. I can't use dorun because even though dorun doesn't realize the 
>    sequence, it can't execute a function on every element.
>    2. I can't use loop recur because it also realizes the sequence: (loop 
>    [a (files) b (first a)] (println b) (recur (rest a) (first a))) 
>    3. I can't use refs because even though they provide state, they can't 
>    save the state of the sequence without realizing the sequence.
>
> My question
> *Should I try the new stream library?*
> *
> *
> Thank you for your time.
>
> -Sean
>
>

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

Reply via email to