This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-08-14
Channels
- # aleph (1)
- # announcements (1)
- # beginners (59)
- # boot (2)
- # calva (5)
- # cider (8)
- # clj-kondo (6)
- # cljdoc (5)
- # cljsrn (11)
- # clojure (123)
- # clojure-dusseldorf (1)
- # clojure-europe (4)
- # clojure-italy (22)
- # clojure-losangeles (4)
- # clojure-nl (10)
- # clojure-spec (18)
- # clojure-uk (22)
- # clojurescript (103)
- # cursive (32)
- # data-science (1)
- # datomic (21)
- # events (2)
- # figwheel (1)
- # fulcro (12)
- # graalvm (3)
- # graphql (8)
- # jobs (2)
- # kaocha (4)
- # klipse (2)
- # lein-figwheel (4)
- # leiningen (23)
- # off-topic (11)
- # planck (11)
- # re-frame (8)
- # reagent (2)
- # reitit (3)
- # rewrite-clj (1)
- # ring (1)
- # ring-swagger (31)
- # schema (2)
- # shadow-cljs (66)
- # spacemacs (3)
- # specter (16)
- # sql (9)
- # tools-deps (16)
- # vim (26)
@puzzler select-one
is the same as select-first
except it enforces that your path navigates to at most one value
corrected the wiki entry on select-first
, thanks for letting me know
you probably want select-one
for your use case
I recall a time when you sketched out a navigator for transforming a nested map in such a way that on the way out, it would recursively delete any keys with empty maps. I can't find it in the slack logs. Do you by any chance have a handy pointer to that?
i asked a similar question here and on SO and posted nathan's answer: https://stackoverflow.com/a/57002777/1185536
I saw that, but it looks like the answers are all about scanning through a whole nested map structure removing nil leaves. That's not really what I want. I want things to get removed if the output of the transformation is NONE, and that causes its map to be empty, and so on.
So something like: (setval (keypath-remove-empties :a :c :d) NONE {:b 1, :a {:c {:d 0}}}) gives back {:b 1}
@puzzler I believe you’re looking for compact
?
user=> (sp/setval (sp/compact :a :c :d) sp/NONE {:b 1, :a {:c {:d 0}}})
{:b 1}
you probably don't want to return NONE if the top-level structure becomes empty, so something like (setval [:a (compact :c :d)] NONE data)
is generally the pattern to use
I've finally figured out why I can't use filterer
after MAP-KEYS; it expects a sequence where MAP-KEYS navigates to a view of many keyword (for me) elements
Which is better: (setval [MAP-KEYS #(#{"a"} (namespace %))] NONE mymap)
or: (setval [(filterer [FIRST NAMESPACE #{"a"}]) MAP-KEYS] NONE mymap)
please?
The difference seems more substantial when using select
; the latter form allows me to get the whole entries whereas the former has irrevocably descended to the keys
My initial attempt btw was something like (setval [MAP-KEYS (filterer NAMESPACE #{"a"})] NONE mymap)
@alee you can also do (setval [MAP-KEYS (selected? NAMESPACE (pred= "a"))] NONE mymap)