map-indexed

added
1.2

ns
clojure.core

type
function

(map-indexed f) (map-indexed f coll)

Returns a lazy sequence consisting of the result of applying f to 0
and the first item of coll, followed by applying f to 1 and the second
item in coll, etc, until coll is exhausted. Thus function f should
accept 2 arguments, index and item. Returns a stateful transducer when
no collection is provided.

                user=> (map-indexed (fn [idx itm] [idx itm]) "foobar")
([0 \\f] [1 \\o] [2 \\o] [3 \\b] [4 \\a] [5 \\r])


            
                ;; or simply
user=> (map-indexed vector "foobar")
([0 \\f] [1 \\o] [2 \\o] [3 \\b] [4 \\a] [5 \\r])