This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-01-09
Channels
- # announcements (14)
- # babashka (2)
- # beginners (33)
- # calva (25)
- # cider (4)
- # clj-kondo (14)
- # clojure (11)
- # cursive (4)
- # datomic (3)
- # fulcro (53)
- # gratitude (3)
- # integrant (2)
- # leiningen (7)
- # lsp (10)
- # malli (34)
- # missionary (3)
- # off-topic (71)
- # other-languages (18)
- # pathom (1)
- # practicalli (2)
- # releases (1)
- # ring (4)
- # spacemacs (1)
- # vim (14)
I’d like to perform in some nonintrusive way, such that log/info(:data data)
will make the data to be formatted by default.
(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 clojure.tools.logging to pprint.
I grabbed that from here https://clojuredocs.org/clojure.pprint/pprint#example-5664a36be4b09a2675a0ba71
it looks like clojure uses that same method internally as well https://github.com/clojure/clojure/blob/clojure-1.10.1/src/clj/clojure/core.clj#L4742-L4743
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)))
https://github.com/weavejester/medley/ also has filter-vals
, but I'd use that library only if you already depend on it.