Fork me on GitHub
#specter
<
2016-10-06
>
yonatanel07:10:47

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}]}]

nathanmarz12:10:10

@yonatanel I don't understand your example

nathanmarz12:10:28

the ids are sometimes under :a and sometimes under :b?

nathanmarz12:10:54

is this recursive or just 2 levels? why is the map with :a 4 getting marked in the example?

nathanmarz12:10:48

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

yonatanel12:10:01

@nathanmarz The ids can have different keys. Only their value matters in this example.

yonatanel12:10:35

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.

nathanmarz12:10:20

I would just do it as two separate transformations

nathanmarz12:10:24

(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))

yonatanel13:10:09

It wouldn't work if I wanted to only mark id 4, but I'll figure it out.

nathanmarz13:10:52

couldn't tell from your example whether the id matching was just on nested maps or on the parent maps as well

nathanmarz13:10:59

not hard to modify to check both

nlessa21:10:51

Hi! Using 0.12.0 version what would be the elegant way to get in a hierarchical map like

{:a 1 :b: 1  :c {:a 2 :b 2 :c {:a 3 :b 3 :c …}…}
- undetermined levels of c - the most profound value of :a ?