如何通过字符串过滤映射并返回匹配(我需要同时过滤键和值)键值对作为字符串。我知道这看起来像一个奇怪的问题,它只是关于学习Clojure。
在此之前,感谢您抽出宝贵的时间。
;my input map ===>
{1 {:id 1c :race "human" :gender "male"}
2 {:id 1a :race "cat" :gender "cfemale"}}
;my filter string
"c"
;my expected output for "c" ===>
[["id" "1c"] ["race" "human"] ["race" "cat"]["gender" "cfemale"]]
;my filter string
"r"
;my expected output for "r" ===>
[["race" "human"] ["race" "cat"]["gender" "cfemale"]["gender" "male"]]
(def my-vec (into [] (for [m (vals my-map) [k v] m] [(name k) v])))
(defn filter-vector-func [coll ?s]
(reduce
(fn [x y]
(let [[first second :as all] y]
(if (str/includes? (str/lower-case all) (str/lower-case ?s))
(conj x all)
x)))
[]
coll))
这是我想要的工作。可以用postwalk来写吗?