MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/Clojure/comments/m7wdbd/clojure_keyword_argument_functions_now_also/grfrce8/?context=3
r/Clojure • u/SimonGray • Mar 18 '21
44 comments sorted by
View all comments
13
A simple example of layering functions that take kwargs:
(defn internal [& {:keys [a b]}] (println "got:" a b)) (defn external [& opts] ;; passes on opts to internal ;; and patches in a default for :a (apply internal :a 1 opts)) (external :a 5 :b 6) got 5 6 (external) got 1 nil
6 u/jjttjj Mar 19 '21 edited Mar 19 '21 Alternatively:(defn external [& {:as opts}] (internal :a 1 opts))Edit: I realized you don't need :keys. Is there a reason to prefer the apply version? 4 u/alexdmiller Mar 19 '21 Right-o - probably better without.
6
Alternatively:
(defn external [& {:as opts}] (internal :a 1 opts))
Edit: I realized you don't need :keys. Is there a reason to prefer the apply version?
:keys
4 u/alexdmiller Mar 19 '21 Right-o - probably better without.
4
Right-o - probably better without.
13
u/alexdmiller Mar 19 '21
A simple example of layering functions that take kwargs: