This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-03-30
Channels
- # babashka (18)
- # beginners (90)
- # calva (33)
- # clara (6)
- # cljfx (11)
- # cljs-dev (22)
- # cljsrn (9)
- # clojure (71)
- # clojure-australia (2)
- # clojure-czech (15)
- # clojure-europe (27)
- # clojure-germany (9)
- # clojure-nl (4)
- # clojure-serbia (3)
- # clojure-uk (10)
- # clojurescript (17)
- # conjure (12)
- # data-oriented-programming (2)
- # deps-new (6)
- # fulcro (29)
- # graphql (10)
- # hugsql (6)
- # jobs (1)
- # lsp (59)
- # malli (8)
- # off-topic (76)
- # pathom (15)
- # polylith (130)
- # re-frame (9)
- # reagent (15)
- # releases (4)
- # rewrite-clj (6)
- # ring (6)
- # rum (9)
- # shadow-cljs (116)
- # specter (5)
- # testing (7)
- # tools-deps (24)
- # vim (6)
- # xtdb (17)
Hey team, noob question (not quite sure how to search for above) I want to do the following:
(def xs [{:name "foo" :x 1}]
(def to-add-a {:name "foo" :x nil})
(def to-add-b {:name "bar" :x nil})
I want to updated xs
, so
a) If the record’s name
matches, we do nothing:
xs + to-add-a => [{:name "foo" :x 1}]
b) but if the record does not exist, to append it:
xs + to add-b => [{:name "foo" :x 1} {:name "bar" :x nil}]
How could I achieve this with spectr?@stopachka this would be one way to do it:
(defn add-record [all record]
(setval [(not-selected? ALL :name (pred= (:name record)))
AFTER-ELEM]
record
all))
niice. Thanks @nathanmarz!
Okay, one more: Say I have
(def name->objects {"foo": [{:name "foo" :x 1]})
(def to-add-a {:name "foo" :x nil})
(def to-add-b {:name "bar" :x nil})
Now, I want to:
a. Either append into existing:
name->objects + to-add-a => {"foo" [{:name "foo" :x 1] {:name "foo" :x nil}]}
b. Or create the key and plop itself in:
name->objects + to-add-b => {"foo" [{:name "foo" :x 1}] "bar" {:name "bar" :x nil}}