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 <[email protected]> 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 [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en