beginners

Richard Nagelmaeker 2025-06-27T17:57:37.554659Z

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.

oddsor 2025-07-02T12:40:55.876669Z

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 πŸ˜…

πŸ‘ 2
Elias W 2025-07-04T10:32:20.389189Z

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

πŸ‘ 3
2025-06-27T17:58:18.129699Z

find returns [key value]

πŸ‘ 3
Richard Nagelmaeker 2025-06-27T18:00:08.523369Z

Cool, thank you.

phronmophobic 2025-06-27T18:09:35.113759Z

find is great. you may also be interested in select-keys

πŸ‘ 1
βœ… 1
Ludger Solbach 2025-06-27T18:32:54.008059Z

I've never used find, as far as I remember. πŸ€” I should put it on the list of clojure functions to try.

πŸ™Œ 1
borkdude 2025-07-03T11:24:46.158519Z

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

πŸ‘ 1