I'd be careful about writing my own version of mapcat.  You might save a call 
or two on the f function, but you'll probably lose in the general.  Try some 
experiments with larger take numbers.  You might be better off concentrating on 
your f function.  I've found that trying to special-case degenerate cases (for 
empty collections, etc.) has actually hurt my performance, presumably because 
my cleverness got in the way of hotspot optimizations.  


On Aug 22, 2011, at 10:32 AM, Asim Jalis wrote:

> user=> (defn f [[x]] (println "computing x:" (inc x)) (vector (inc x)))
> #'user/f
> user=> (->> (iterate f [0]) (take 0))
> ()
> user=> (->> (iterate f [0]) (apply concat) (take 0))
> computing x: 1
> computing x: 2
> computing x: 3
> ()
> user=> (->> (iterate f [0]) (mapcat identity) (take 0))
> computing x: 1
> computing x: 2
> computing x: 3
> ()
> 
> Is there a way to rewrite mapcat (or apply concat) so that they don't
> evaluate the incoming seq unnecessarily?
> 
> -- 
> 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 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