Anton Harald
Anton Harald

Reputation: 5944

Keep certain keys of a hash-map

What would be a quick way to keep only certain keys from a hash-map?

(def m {:a 1 :b 2 :c 3 :d 4})

explicit version:

((fn [{:keys [b c]}] {:b b :c c})
 m)
;= {:b 2, :c 3}

Upvotes: 2

Views: 122

Answers (1)

Lee
Lee

Reputation: 144136

select-keys:

(select-keys m [:b :c])

Upvotes: 7

Related Questions