On Sun, May 23, 2010 at 21:21, Michael Gardner <gardne...@gmail.com> wrote:
> I need to use a predicate to divide one list into two, one containing all 
> values for which the predicate is true, and the other with all remaining 
> values. I can do this easily by filtering twice, once with the predicate and 
> once with its complement, but is there some core or contrib function that 
> will do this more directly and efficiently? I'm not sure what the best way to 
> search for something like this would be.

Yes and No.

Yes: such a function exists: clojure.contrib.seq-utils/separate

No: It's not as efficient as you'd like. It does just what you
describe in your post: it filters twice.

(defn separate
  "Returns a vector:
   [ (filter f s), (filter (complement f) s) ]"
  [f s]
  [(filter f s) (filter (complement f) s)])

// Ben

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