Filter nil values from Clojure map?

后端 未结 5 2121
遥遥无期
遥遥无期 2021-02-12 14:42

What is the best way to filter nil values from a Clojure map {}?

{ :a :x :b nil :c :z }
;;=>  { :a :x, :c :z }
5条回答
  •  生来不讨喜
    2021-02-12 15:20

    I use following code:

    (into {} (filter val {:a 1, :b 2, :c nil}))
    ;;=> {:a 1, :b 2}
    

    NOTE: this will remove false values as well as nils

提交回复
热议问题