This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-10-06
Channels
- # aleph (79)
- # bangalore-clj (3)
- # beginners (49)
- # boot (74)
- # cider (10)
- # cljs-dev (21)
- # cljsrn (2)
- # clojure (105)
- # clojure-berlin (1)
- # clojure-brasil (1)
- # clojure-dusseldorf (1)
- # clojure-korea (1)
- # clojure-poland (3)
- # clojure-russia (38)
- # clojure-spec (146)
- # clojure-uk (20)
- # clojurescript (70)
- # cloverage (1)
- # component (1)
- # core-async (23)
- # css (16)
- # cursive (22)
- # datascript (1)
- # datomic (22)
- # defnpodcast (6)
- # emacs (60)
- # events (1)
- # hoplon (94)
- # jobs (1)
- # jobs-rus (13)
- # luminus (11)
- # off-topic (11)
- # om (48)
- # onyx (5)
- # proton (7)
- # re-frame (87)
- # reagent (39)
- # rethinkdb (1)
- # ring-swagger (14)
- # rum (6)
- # specter (14)
- # untangled (105)
- # vim (6)
- # yada (22)
Is it possible to transform a map according to a transformation that already happened in a nested map? I have nested objects that need to be marked if they have a certain ID, and if they contain a marked object they should also be marked. For example:
[{:a 1 :bs [{:b 2} {:b 3}]}
{:a 4 :bs [{:b 5} {:b 6}]}]
;; 1, 2 and 6 need to be marked, and also those that contain them:
[{:a 1 :mark true :bs [{:b 2 :mark true} {:b 3}]}
{:a 4 :mark true :bs [{:b 5} {:b 6 :mark true}]}]
@yonatanel I don't understand your example
the ids are sometimes under :a
and sometimes under :b
?
is this recursive or just 2 levels? why is the map with :a 4 getting marked in the example?
oh i see, you want to mark the parent if the child gets marked, still don't understand when to look at :a
vs :b
@nathanmarz The ids can have different keys. Only their value matters in this example.
Frankly it's not recursive, just up to 2 levels deeps, but a few hours ago I thought I might need it recursive. It might be only 1 level though.
I would just do it as two separate transformations
(def data
[{:a 1 :bs [{:b 2} {:b 3}]}
{:a 4 :bs [{:b 5} {:b 6}]}])
(->> data
(setval [ALL
:bs
ALL
(selected? :b #{1 2 6})
:mark]
true)
(setval [ALL
(selected? :bs ALL (must :mark))
:mark]
true))
couldn't tell from your example whether the id matching was just on nested maps or on the parent maps as well
not hard to modify to check both