假设我们有这个嵌套的向量:
(def coll [nil [["this" nil "this"] nil] nil "this"])
Run Code Online (Sandbox Code Playgroud)
你会如何设计一个remove-nil函数,以便所有nil消失?
(remove-nil coll)
;> [[["this" "this"]] "this"]
Run Code Online (Sandbox Code Playgroud)
(clojure.walk/postwalk #(if (coll? %) (into (empty %) (remove nil? %)) %) coll)
;=> [[["this" "this"]] "this"]
Run Code Online (Sandbox Code Playgroud)