chickadee » vector-lib » vector-map

vector-map f vec_1 vec_2 ···procedure

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 i (vector-ref vec_1 i) (vector-ref vec_2 i) ···). The dynamic order of application of f is unspecified.

Examples:

(vector-map (λ (i x) (* x x))
            (vector-unfold (λ (i x) (values x (+ x 1))) 4 1))
  ;=> #(1 4 9 16)
(vector-map (λ (i x y) (* x y))
            (vector-unfold (λ (i x) (values x (+ x 1))) 5 1)
            (vector-unfold (λ (i x) (values x (- x 1))) 5 5))
  ;=> #(5 8 9 8 5)
(let ((count 0))
 (vector-map (λ (ignored-index ignored-elt)
               (set! count (+ count 1))
               count)
             '#(a b)))
  ;=> #(1 2) OR #(2 1)
(vector-map (λ (i elt) (+ i elt))
            '#(1 2 3 4))
  ;=> #(1 3 5 7)