Logo

Programming-Idioms

History of Idiom 7 > diff from v87 to v88

Edit summary for version 88 by cc:
[Clojure] a

Version 87

2020-05-10, 21:54:27

Version 88

2020-08-07, 21:15:55

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

Variables
i,x,items
Variables
i,x,items
Extra Keywords
traverse traversal
Extra Keywords
traverse traversal
Code
(doseq [[i x] (map-indexed vector items)]
  (println i ":" x))
Code
(let [
        total (reduce + arr)
        values (map-indexed #((sum4 %2 %1) arr))
    ] (print values) )
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. doseq is used 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. doseq is used for side-effects.
Doc URL
http://clojuredocs.org/clojure.core/map-indexed
Doc URL
http://clojuredocs.org/clojure.core/map-indexed