On Sun, May 19, 2013 at 4:54 PM, Jim - FooBar(); <jimpil1...@gmail.com>wrote:

>  ha! you cheated with iterate...
>
> try this which is closer to the example...
>
> (first (filter odd? (map #(do (println "realized " %) %)  [2 4 6 7 8 9])))
> realized  2
> realized  4
> realized  6
> realized  7
> realized  8
> realized  9
> 7
>
> Jim
>

=> (some #(when (odd? %) %)
         (map #(do (println "realized" %) %)
              [2 4 6 7 8 9]))
realized 2
realized 4
realized 6
realized 7
realized 8
realized 9
7

;)

In fact, just calling 'first' on a mapped sequence gives the same behaviour:

=> (first (map #(do (println "realized" %) %)
               [2 4 6 7 8 9]))
realized 2
realized 4
realized 6
realized 7
realized 8
realized 9
2

That said, 'some' does avoid realizing the first 32 elements if it's a vec.
I still don't
think you should care about that though - that's kind of the point of
laziness, to be
able to use map/filter etc without caring about how much is realized.

Jonathan

-- 
-- 
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/groups/opt_out.


Reply via email to