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