Try clojure.contrib.seq-utils :)

As a learning exercise, I'd recommend re-writing it to be lazy.  Your
version is eager because it uses loop.  In order to make it lazy,
you'd want to construct a lazy-seq.  See the macro w/ the same name.

Another choice is to use built-in functions, like this:

(defn positions [pred coll]
  (map second
    (filter (comp pred first)
      (map vector coll (iterate inc 0)))))

Hope this helps,
Sean

On Nov 19, 1:07 pm, nchubrich <nicholas.chubr...@gmail.com> wrote:
> Is this function part of the API or any contrib?  I couldn't find it:
>
> (defn positions [pred coll]
>   (loop [coll coll i 0 accum []]
>     (if (empty? coll) accum
>       (if (pred (first coll))
>         (recur (rest coll) (inc i) (conj accum i))
>         (recur (rest coll) (inc i) accum)))))

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