Logo

Programming-Idioms

History of Idiom 7 > diff from v72 to v73

Edit summary for version 73 by finalfantasia:
[Clojure] update "Explain stuff"

Version 72

2019-09-26, 18:01:57

Version 73

2019-09-26, 18:03:29

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
(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 sequence which contains in each element the index of each one and its original value in items. run! is used for side-effects.
Doc URL
http://clojuredocs.org/clojure.core/map-indexed
Doc URL
http://clojuredocs.org/clojure.core/map-indexed