How to remove multiple keys from a map?

前端 未结 4 609
难免孤独
难免孤独 2020-12-29 20:13

I have a function that removes a key from a map:

(defn remove-key [key map]
  (into {}
        (remove (fn [[k v]] (#{key} k))
                map)))

(remov         


        
4条回答
  •  长发绾君心
    2020-12-29 20:52

    Your remove-key function is covered by the standard library function dissoc. dissoc will remove more than one key at a time, but it wants the keys to be given directly in the argument list rather than in a list. So you can use apply to "flatten" it out.

    (apply dissoc {:foo 1, :bar 2, :baz 3} [:foo :bar])
    ==> {:baz 3}
    

提交回复
热议问题