This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-10-17
Channels
- # announcements (7)
- # beginners (9)
- # calva (17)
- # clj-kondo (11)
- # clojure (68)
- # clojure-austin (2)
- # clojure-bay-area (3)
- # clojure-europe (19)
- # clojure-gamedev (10)
- # clojure-nl (1)
- # clojure-norway (73)
- # clojure-spec (5)
- # clojure-uk (5)
- # clojuredesign-podcast (6)
- # clojurescript (65)
- # community-development (28)
- # conjure (1)
- # datahike (34)
- # datomic (36)
- # emacs (11)
- # funcool (1)
- # helix (13)
- # honeysql (36)
- # hyperfiddle (15)
- # jobs (1)
- # jobs-discuss (4)
- # malli (13)
- # nbb (21)
- # off-topic (51)
- # practicalli (20)
- # reitit (1)
- # releases (1)
- # ring (4)
- # squint (1)
- # tools-deps (14)
- # transit (8)
A few times now I've had a multi arity function where I had a let binding in each arity that was basically the same. Is there a way to only have to write this let binding once for all arities?
Show us code. Hard to know what you're describing otherwise.
(I haven't needed "a let binding in each arity that was basically the same" so I'm not sure what you're trying to do)
(defn format-query
([a] (let [calculated-a (somefunction a)
other-stuff-based-on-calculated-a (-> calculated-a
otherfunction
str)]
(format query-defined-elsewhere calculated-a other-stuff-based-on-calculated-a "")))
([a b] (let [calculated-a (somefunction a)
other-stuff-based-on-calculated-a (-> calculated-a
otherfunction
str)]
(format query-defined-elsewhere calculated-a other-stuff-based-on-calculated-a b))))
I basically format the query in the exact same way between the two but have the additional b
parameter
You can have one arity call the other passing the missing param, i.e.
(defn format-query
([a] (format-query a ""))
([a b] (let [calculated-a (somefunction a)
other-stuff-based-on-calculated-a (-> calculated-a
otherfunction
str)]
(format query-defined-elsewhere calculated-a other-stuff-based-on-calculated-a b))))
➕ 5
of course
thank you