mapv applies a function across one or more seqable collections and returns the results in a persistent vector. With multiple collections, it stops at the shortest. section 12.8
Use mapv when eager vector output matters:
- Unlike map, mapv returns a vector and fully consumes lazy inputs. section 12.8
- The function’s arity must match the number of collections; nil collections behave as empty collections. section 12.8
- Incorrect function arity, a non-function, or a non-seqable collection produces an exception. section 12.8
- mapv has no single-arity transducer form; use transducer-based vector construction for other sequence operations. section 12.8
Element-wise transformation
(mapv inc [0 1 2 3]) ;; [1 2 3 4] (mapv hash-map [:a :b :c] (range)) ;; [{:a 0} {:b 1} {:c 2}]
Composing vector operations
(defn scalar-multiply [c a] (mapv (partial * c) a)) (scalar-multiply 3 [1 2 3]) ;; [3 6 9] (add [1 2] [3 4]) ;; [4 6]
Listing 12.5. → Sequence processing, Higher-order functions
(mapv ([f coll]) ([f c1 c2]) ([f c1 c2 c3]) ([f c1 c2 c3 & colls]))
Inspect mapv’s supported arities, from one collection through additional collections. section 12.8
