Fork me on GitHub

I am logging some map, how can I enable pretty print on the format?


I’d like to perform in some nonintrusive way, such that log/info(:data data) will make the data to be formatted by default.

Cora (she/her)04:01:05

(with-out-str (clojure.pprint/pprint {:x 1 :y -1}))
;; => "{:x 1, :y -1}\n"


It’s more like I am going to switch the internal print function of to pprint.


is there any smart way of not adding a map key if the value is nil ? I'm parsing an XML with riveted and I have things like:

(defn entity-relation-keymap->map
  [^Navigator e]
  {:field-name (vtd/attr e :field-name)
   :rel-field-name (vtd/attr e :rel-field-name)})
:rel-field-name is very often nil so I would like to NOT add it in the first place. Is there something like (when-let [elem ] add elem to map ? I'm thinking something like reader conditional / macro ?! Right now I use, which works - but maybe I can avoid adding them in the first place ?!
(defn clean-nils [m]
  (into {} (filter (comp some? val) m)))  


If it's just a few predefined keys, I'd use let + cond-> + assoc:

(let [b (get-b)]
  (cond-> {:a (get-a)}
    b (assoc :b b)))

p-himik20:01:28 also has filter-vals, but I'd use that library only if you already depend on it.