Clojure:删除嵌套数据结构中所有nil项的最简单方法是什么?

leo*_*bot 2 null clojure

假设我们有这个嵌套的向量:

(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)

A. *_*ebb 5

(clojure.walk/postwalk #(if (coll? %) (into (empty %) (remove nil? %)) %) coll)
;=> [[["this" "this"]] "this"]
Run Code Online (Sandbox Code Playgroud)