This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-02-22
Channels
- # architecture (9)
- # beginners (90)
- # cider (98)
- # cljs-dev (23)
- # cljsrn (4)
- # clojure (101)
- # clojure-brasil (3)
- # clojure-dev (48)
- # clojure-italy (15)
- # clojure-losangeles (3)
- # clojure-russia (12)
- # clojure-uk (17)
- # clojured (1)
- # clojurescript (141)
- # community-development (15)
- # core-async (1)
- # datascript (12)
- # datomic (18)
- # docker (3)
- # emacs (1)
- # events (1)
- # figwheel (1)
- # fulcro (57)
- # graphql (4)
- # javascript (9)
- # jobs (1)
- # lein-figwheel (1)
- # leiningen (1)
- # lumo (1)
- # off-topic (68)
- # om (9)
- # om-next (3)
- # onyx (4)
- # parinfer (6)
- # pedestal (14)
- # portkey (2)
- # proton (1)
- # protorepl (19)
- # re-frame (57)
- # reagent (46)
- # ring-swagger (12)
- # shadow-cljs (167)
- # slack-help (5)
- # specter (18)
- # sql (1)
- # uncomplicate (3)
- # unrepl (1)
I’m struggling to understand compact
. in the example, shouldn’t the :c that has a value be left alone?
(setval [ALL :a (compact :c)]
NONE
[{:a {:b 1 :c 2}}
{:a {:b 1 :c nil}}])
=>
[{:a {:b 1}} {:a {:b 1}}]
the docstring says that it only applies when the value is empty. that is exactly what I want but I’m missing how to make that work
@steveb8n compact
applies to the value being navigated on, in this case the submaps
e.g.
(setval [ALL :a (compact :c)]
NONE
[{:a {:c 2}}
{:a {:b 1 :c nil}}])
;; => [{} {:a {:b 1}}]
That makes sense. Reading that expression it makes sense that it unconditionally removes the value.
But what if I want to conditionally remove it i.e. when value is nil. Is there an idiomatic way to do that? The docstring suggests that behaviour, hence my confusion.
I can write a transform fn or conditional navigation but wonder if you would use compact or some other elegance for that as well?
@steveb8n it's just (setval [ALL :a :c nil?] NONE data)
i’m just trying out specter. what’s the best way to select-keys at various levels of a tree:
;; input
{:a {:aa 1 :ab 2 :ac 3}
:b {:ba 10 :ba 11}
:c {:ca 100}}
;; desired output
{:a {:aa 1 :ab 2}
:c {:ca 100}}
@sashton to maintain the structure of the input, select what to remove rather than what to keep:
(setval (multi-path :b [:a :ac]) NONE data)
thanks @nathanmarz. is remove the only option? the data i’m looking at has lots of extra fields which i’m not interested in. while i could list all the fields to delete, it might get tedious.
there's also the submap
navigator which for selects is equivalent to select-keys
though it currently changes sorted maps to unsorted maps if used in a select
https://github.com/nathanmarz/specter/issues/235
this is how you could go about doing it with submap
:
(defdynamicnav viewed [path viewnav]
(transformed path (fn [s] (select-any viewnav s)))
)
(select-any [(viewed :a (submap [:aa :ab])) (submap [:a :c])] data)