This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-05-03
Channels
- # aws (6)
- # babashka (77)
- # beginners (102)
- # clj-kondo (24)
- # cljsrn (17)
- # clojure (40)
- # clojure-australia (15)
- # clojure-europe (50)
- # clojure-nl (4)
- # clojure-uk (4)
- # clojurescript (9)
- # conjure (2)
- # cursive (28)
- # data-science (1)
- # datomic (21)
- # events (5)
- # joker (15)
- # malli (136)
- # meander (1)
- # off-topic (25)
- # pathom (4)
- # podcasts-discuss (2)
- # portal (12)
- # portkey (1)
- # powderkeg (1)
- # practicalli (5)
- # re-frame (14)
- # reitit (3)
- # shadow-cljs (49)
- # specter (4)
- # tools-deps (4)
- # unrepl (1)
Hi folks again 😄
How would I go if I wanted to set a key in a map that is missing?
For instance I only want to add :foo nil
if it's not already there
this is what I have come up so far:
(defn assoc-mode-nils
"Add nil to empty modes."
[root]
;; Please do not remove this or you will break spec and frontend.
(sp/transform
[maps/POST-ORDER-TREE-VALS
(sp/must :descriptor)
(sp/pred #(= (:type %) enum/segmod-element-type-heart-lv-subsegment))
(sp/multi-path [(sp/keypath (keyword cmr.scoring/mode-function)) (sp/nil->val nil)]
[(sp/keypath (keyword cmr.scoring/mode-edema)) (sp/nil->val nil)])]
identity
root))
(s/setval [(s/cond-path (s/not-selected? (s/map-key :a)) (s/keypath :a))] 2 {:a nil :b 4})
=> {:a nil, :b 4}
(s/setval [(s/cond-path (s/not-selected? (s/map-key :a)) (s/keypath :a))] 2 {:a 10 :b 4})
=> {:a 10, :b 4}
(s/setval [(s/cond-path (s/not-selected? (s/map-key :a)) (s/keypath :a))] 2 {:b 4})
=> {:b 4, :a 2}
not sure if there’s a better way