我已将我的数据建模为嵌入式向量。我需要找出这些向量中是否存在一个元素。我有下面的代码可以正确执行。但是,我想就更惯用的方式提出建议。
(defn exists-in-vector?
[my-vec my-sym]
(= my-sym (first my-vec)))
(defn exists-in-vectors?
[all-vectors my-symbol]
(empty? (for [first-vector all-vectors
second-vector first-vector
third-vector second-vector
:when (exists-in-vector? third-vector my-symbol)
:while (exists-in-vector? third-vector my-symbol)]
true)))
> (exists-in-vectors? [[[[:a 20] [:b :30]] [[:c 20] [:d :30]]]
[[[:h 20] [:g :30]] [[:f 20] [:e :30]]]]
:a) => true