Is there a variant of the get function in Clojure, which in a map allows me to retrieve both the key and itβs value ?
Map {:a 1 :b 2 :c}
Give me :b
Returns {:b 2}
I understand I can easily make this myself. Just wondered if such a function is part of Clojure's core. I havn't found it yet.Love that Iβve been programming Clojure for around 6-7 years, and I canβt recall having seen/used find!
Always some undiscovered gems in clojure.core π
Note that find returns a MapEntry, not a vector, although it is printed like a vector. So you can do:
(key (find {:a 5 :b 6} :b))
But not
(key ([:b 6]))
(Same for val of course.)
find returns [key value]
Cool, thank you.
find is great. you may also be interested in select-keys
I've never used find, as far as I remember. π€ I should put it on the list of clojure functions to try.
It's pretty hard to find find even with re-find if you're not sure what you want the output to look like. But if you can be a little bit more vague (instead of concrete about the shape of the input/output) ChatGPT gave the right answer
https://chatgpt.com/share/6866682e-b4f8-8012-8c4e-49dfb3b82dda
First I asked about something more concrete and it only came up with select-keys