Reputation: 11734
I have three vectors:
(def v1 ["one" "two" "three"])
(def v2 ["one" "two" "three" "four"])
(def v3 ["one" "two" "three" "four" "five"])
I need to ensure that the size of the vectors is always 5 elements. I want a function to pass each to which will check the size and conj empty strings as placeholders for when the size is less than 5 such that I get:
(def new-v1 ["one" "two" "three" "" ""])
(def new-v2 ["one" "two" "three" "four" ""])
(def new-v3 ["one" "two" "three" "four" "five"])
Thanks.
Upvotes: 0
Views: 137
Reputation: 17859
you can make a lazy seq of your vector ++ repeated empty string, and take 5 elements from it:
(defn process [items]
(into [] (take 5 (concat items (repeat "")))))
user> (process ["a" "b"])
["a" "b" "" "" ""]
Upvotes: 3