On Nov 19, 11:18 am, capricorn20 <[EMAIL PROTECTED]> wrote:
> I want create seq which keep indexes of non-zero elements of
> collection.
> Code:
>
> (defn nonzero-inx [s]
>   (filter (fn [x] (not (nil? x))) (map (fn [a b] (if (not (== a 0))
> b)) s (range (count s)))))
>
> look complicated than solution in most imperative languages.
> May be possible simplest way in Clojure?

You are on the right track, this a bit more succinct:

(defn nonzero-idxs [s]
  (remove nil?
    (map #(when-not (zero? %1) %2)
         s (iterate inc 0))))

Rich
--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to