On Jan 25, 2009, at 5:24 PM, e wrote:

Do folks in the contrib group like this new implementation?

To make contributions to clojure-contrib, you'll need to have a Contributor Agreement on file with Rich. Please see http://clojure.org/contributing .

I think your implementation is an improvement over the current clojure.contrib.seq-utils/separate.

I have some suggestions:

- there's precedent for functions that do one thing or another based on a predicate to be named with a "-by" suffix. - using vectors for the intermediate results will allow the separated outputs to preserve the order of the input which might be helpful to some callers. Since it will still give good performance, I'd opt for that and promise it in the doc string. - you might also consider using the names first and rest for the destructured names you called f and r. I would imagine that's a bit controversial (because the local names would shadow useful functions), but arguably it would make the implementation easier to read.
        - returning a vector of vectors seems good to me.

Here's an implementation:

user>  (defn separate-by [pred coll]
         (loop [in [] out [] [f & r] coll]
           (if f
             (if (pred f)
               (recur (conj in f) out r)
               (recur in (conj out f) r))
             [in out])))

#'user/separate-by
user> (separate-by odd? [1 2 3 4 5 6 7])
[[1 3 5 7] [2 4 6]]
user>

Whatever you propose will need a doc string.

After Rich receives your Contributor Agreement and your name is up on the clojure.org/contributing page, please enter an issue against clojure-contrib noting that your alternate implementation for the current clojure.contrib.seq-utils/separate has higher performance while still being maintainable and correct. Include a complete copy of the code you propose, preferably as a patch.

Once the issue is up, I'd follow up in this thread with the issue number requesting that Stuart consider resolving the issue by adopting your contribution.

--Steve

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to