Fork me on GitHub
#clojure-europe
<
2022-07-23
>
ray09:07:25

Good morning

ray09:07:03

Weekend Clojure trivial discussion: optional maps / keys or multi-arity functions? Feels like 1.11 changes made the optional maps / keys a lot easier. I have largely abandoned multi arity functions in favour of this style. Thoughts?

👀 1
🌼 1
Ben Sless15:07:53

It's easier and more readable but I'm not a fan of the overhead :thinking_face: I prefer an options map

borkdude11:07:46

@raymcdermott IMO Clojure 1.11 allows you to now call named varargs fns with 1 map so we now can just use maps everywhere as arguments and deprecate those named varargs fns forever and have the same style throughout. IMO it wasn't introduced to encourage people to write more varargs functions.

ray12:07:12

I usually have one or two needed things per fn that I can't provide defaults. I used to add defaults via multiple arities. Now I use these optional maps. But yeah - that style was possible before 1.11, maybe it just clicked for me properly as a result of that change. Maybe it just shows my ignorance more than I hoped 😂

borkdude12:07:05

Beware of this pitfall:

(defn foo [{:keys [a] :or {a 2} :as m}] (:a m))
(foo {})

ray13:07:36

:man-shrugging::skin-tone-2:

otfrom16:07:22

I have to admit it still hasn't clicked with me yet

borkdude19:07:44

@otfrom without trying that in the REPL, what do you expect the last expression to return?

ray21:07:13

I'm expecting 2, anything else is :ladybug: 🐛

borkdude21:07:38

sorry to disappoint you

😂 3
otfrom22:07:44

Yeah, I would have guessed 2

otfrom22:07:24

I think more when I want to use them new style and what the trade offs are