> ...repeated creation of the ephemeral vectors isn't too expensive.

With Clojure, although it looks like the immutable vectors are being
re-created on each iteration, under the covers it's really just
pointers being updated and the operations are (about) as efficient as
a loop/recur method.

> ...I don't want to traverse the collection twice.

Yes, I guess that even though each filter clause is lazy they each
will pass through the entire collection once.


On Sun, Mar 8, 2009 at 7:53 AM, David Sletten <da...@bosatsu.net> wrote:
>
>
> On Mar 7, 2009, at 7:17 PM, Adrian Cuthbertson wrote:
>
>>
>> That's the beauty of this language - there are many ways to skin
>> the cat!
>
> Hmmm...I'm not sure what I'll do with a skinless cat. :)
>
>> Here's a version using reduce...
>>
>> (defn filt-split [pred col]
>>  (reduce (fn [[a b] x] (if (pred x) [(conj a x) b] [a (conj b x)]))
>> [[] []] col))
>>
>> (filt-split even? [1 2 3 4 5 6 7 8])
>> [[2 4 6 8] [1 3 5 7]]
>>
>
> I like that a lot. As long as the repeated creation of the ephemeral
> vectors isn't too expensive.
>
>> But when you look at separate in clojure.contrib.seq-utils its simple
>> and elegant;
>> (defn separate [f s]
>>  [(filter f s) (filter (complement f) s)])
>>
>
> This is exactly what I'm trying to avoid. I don't want to traverse
> the collection twice.
>
> Aloha,
> David Sletten
>
>
> >
>

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

Reply via email to