On Fri, Jan 9, 2009 at 9:08 PM, James Reeves <[email protected]> wrote:
>
> On Jan 10, 12:22 am, wubbie <[email protected]> wrote:
>> How can you add line numbers for each line printed from the file.
>> Without line number, I have this:
>>
>> (with-open [rdr (reader "executors.clj")]
>>   (filter #(println %) (line-seq rdr)))
>
> I don't believe there's a function to do this, but it's easy enough to
> add one:
>
> (defn zip-index [coll]
>  (map vector coll (iterate inc 0)))
>
> This will create a sequence of items paired with their indexes:
>
> => (zip-index [:a :b :c])
> ([:a 0] [:b 1] [:c 2])

In clojure.contrib.seq-utils, there is indexed, which is nearly
exactly the same:

user> (clojure.contrib.seq-utils/indexed [:a :b :c])
([0 :a] [1 :b] [2 :c])

k

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to [email protected]
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