chickadee » srfi-133 » vector-map

vector-map f vec1 vec2 ...procedure

[R7RS-small] Constructs a new vector of the shortest size of the vector arguments. Each element at index i of the new vector is mapped from the old vectors by (f (vector-ref vec1 i) (vector-ref vec2 i) ...). The dynamic order of application of f is unspecified.

Examples:

(vector-map (lambda (x) (* x x))
              (vector-unfold (lambda (i x) (values x (+ x 1))) 4 1))
 ;=> #(1 4 9 16)

(vector-map (lambda (x y) (* x y))
              (vector-unfold (lambda (x) (values x (+ x 1))) 5 1)
              (vector-unfold (lambda (x) (values x (- x 1))) 5 5))
 ;=> #(5 8 9 8 5)

(let ((count 0))
   (vector-map (lambda (ignored-elt)
                 (set! count (+ count 1))
                 count)
               '#(a b)))
 ;=> #(1 2) OR #(2 1)