Logo

Programming-Idioms

History of Idiom 7 > diff from v69 to v70

Edit summary for version 70 by finalfantasia:
[Clojure] remove old, less idiomatic version

Version 69

2019-09-26, 17:55:15

Version 70

2019-09-26, 17:55:44

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

Extra Keywords
traverse traversal
Extra Keywords
traverse traversal
Code
(doseq [[value index] (map vector items (range))]
  (println index ": " value))

(run! (fn [[i x]] (println i ":" x))
      (map-indexed vector items))
Code
(run! (fn [[i x]] (println i ":" x))
      (map-indexed vector items))
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.
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/map-indexed
Doc URL
http://clojuredocs.org/clojure.core/map-indexed