如果矢量大小小于一定量,则conj到clojure矢量

时间:2016-02-29 14:31:48

标签: clojure

我有三个向量:

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"])

感谢。

1 个答案:

答案 0 :(得分:3)

你可以使你的vector ++的lazy seq重复空字符串,并从中获取5个元素:

(defn process [items]
  (into [] (take 5 (concat items (repeat "")))))

user> (process ["a" "b"])
["a" "b" "" "" ""]