This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-03-24
Channels
- # aleph (4)
- # beginners (93)
- # cider (7)
- # cljs-dev (16)
- # cljsrn (5)
- # clojure (192)
- # clojure-dusseldorf (3)
- # clojure-italy (14)
- # clojure-russia (16)
- # clojure-serbia (1)
- # clojure-spec (85)
- # clojure-taiwan (1)
- # clojure-uk (79)
- # clojurescript (188)
- # code-reviews (9)
- # core-async (2)
- # crypto (1)
- # cursive (26)
- # datomic (21)
- # heroku (1)
- # hoplon (3)
- # jobs (7)
- # jobs-discuss (20)
- # jobs-rus (13)
- # off-topic (77)
- # om (15)
- # onyx (23)
- # pedestal (94)
- # planck (11)
- # proton (10)
- # protorepl (1)
- # re-frame (16)
- # ring (22)
- # ring-swagger (9)
- # rum (2)
- # specter (18)
- # testing (2)
- # untangled (14)
- # vim (12)
- # yada (58)
hi: If i have a nested map like this map1 {:a [{:b 1 c:3} {:b 2 c:0}] :b 0 }
I need to update :b
key based on the :c
from one of these nested maps under :a
and I have a filter function fn1 to select it based on :c
value . is this the right way to do it?
(transform [(collect :a ALL (selected? [:c ?fn1]) :b) :b] (fn [new old] new) map1)
the code isn't matching up with your description
the code is collecting :b
values, not :c
values
you're also collecting a sequence of values, not "one of" the values
yes it is collecting :b
value, but using :c
values to select which map to collect :b
values from. so if fn1 is ??even
it will return [1] while ?odd
will return [2].
I think you have that reversed
if fn1 is odd?
it will collect [1]
but yea, the code looks correct as long as you're looking to set :b
in the top-level map to a sequence
also you don't need the [...]
in selected?
(selected? :c fn1)
I mean, it will execute but collected values will be ignored
How do I prune a map in specter? select only selects the values, but I want something like a recursive select-keys
. I can’t find a good example of this on the wiki
@borkdude you can do something like this:
(def data {:a {:a 1 :b 2 :c 3} :b {:a 1 :b 2 :c 3 :d 4} :c {:a 1}})
(def ALL-MAPS
(recursive-path [] p
(if-path map?
(stay-then-continue
MAP-VALS p)
)))
(transform ALL-MAPS #(select-keys % [:a :b]) data)
;; => {:a {:a 1, :b 2}, :b {:a 1, :b 2}}