Logo

Programming-Idioms

History of Idiom 7 > diff from v27 to v28

Edit summary for version 28 by :

Version 27

2015-09-03, 13:08:10

Version 28

2015-09-03, 13:13:42

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Idiom #7 Iterate over list indexes and values

Print each index i with its value x from an array-like collection items

Code
(doseq [[value index] (map vector items (range))]
  (println index ": " value))
Comments bubble
items can be any Clojure collection (vector, list, set, map). We construct a new list which contains in each element the index of each one and its original value in items. doseq is use for side-effects.
Doc URL
http://clojuredocs.org/clojure.core/doseq