我有三个向量:
final String realPath = ServletContext.getRealPath("/WEB-INF/resources/images/disegno.svg");
final InputStream = new FileInputStream(realPath);
我需要确保向量的大小总是5个元素。我想要一个函数来传递每个将检查大小和结合空字符串作为占位符,当大小小于5时,我得到:
(def v1 ["one" "two" "three"])
(def v2 ["one" "two" "three" "four"])
(def v3 ["one" "two" "three" "four" "five"])
感谢。
答案 0 :(得分:3)
你可以使你的vector ++的lazy seq重复空字符串,并从中获取5个元素:
(defn process [items]
(into [] (take 5 (concat items (repeat "")))))
user> (process ["a" "b"])
["a" "b" "" "" ""]