public
Last active

Config using optional named parameters

  • Download Gist
optional-config.clj
Clojure
1 2 3 4 5 6 7 8 9 10 11
(def ^:dynamic *config* nil)
 
(defn save [data & {:keys [config] :or {config *config*}}]
(println (format "Saved %s with %s" data config)))
 
;; => (save {:a 5 :b 6} :config {:some :config})
;; Saved {:a 5, :b 6} with {:some :config}
;; nil
;; => (binding [*config* {:some :config}] (save {:a 5 :b 6}))
;; Saved {:a 5, :b 6} with {:some :config}
;; nil

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.