如果向量大小小于一定量,则连接到clojure向量
我有三个向量:如果向量大小小于一定量,则连接到clojure向量,clojure,Clojure,我有三个向量: (def v1 ["one" "two" "three"]) (def v2 ["one" "two" "three" "four"]) (def v3 ["one" "two" "three" "four" "five"]) 我需要确保向量的大小始终为5个元素。我想要一个函数传递给每个函数,当大小小于5时,该函数将检查大小并将空字符串作为占位符连接,这样我可以得到: (def new-v1 ["one" "two" "three" "" ""]) (def new-v2 ["
(def v1 ["one" "two" "three"])
(def v2 ["one" "two" "three" "four"])
(def v3 ["one" "two" "three" "four" "five"])
我需要确保向量的大小始终为5个元素。我想要一个函数传递给每个函数,当大小小于5时,该函数将检查大小并将空字符串作为占位符连接,这样我可以得到:
(def new-v1 ["one" "two" "three" "" ""])
(def new-v2 ["one" "two" "three" "four" ""])
(def new-v3 ["one" "two" "three" "four" "five"])
谢谢。您可以为vector++重复的空字符串创建一个惰性seq,并从中提取5个元素:
(defn process [items]
(into [] (take 5 (concat items (repeat "")))))
user> (process ["a" "b"])
["a" "b" "" "" ""]
您可以为vector++重复的空字符串创建一个惰性seq,并从中获取5个元素:
(defn process [items]
(into [] (take 5 (concat items (repeat "")))))
user> (process ["a" "b"])
["a" "b" "" "" ""]
太完美了!谢谢,太完美了!谢谢