Fork me on GitHub
#specter
<
2017-04-26
>
sophiago13:04:24

@nathanmarz thanks again for all the help again the other day! I just wanted to clarify one thing, this function you gave me for filtering out empty lists isn't working: (setval [LEAVES ALL #(= [] %)] NONE *map*). It seems like it should so I'm a bit confused.

nathanmarz13:04:00

seems to be working fine

user=> (def LEAVES
  #_=>   (recursive-path [] p
  #_=>     (if-path map?
  #_=>       [MAP-VALS p]
  #_=>       STAY
  #_=>       )))
#'user/LEAVES
user=> (def m {0 {1 [[1 2 3] [] [4]]} 2 [[] [] [5 6]]}) 
#'user/m
user=> (setval [LEAVES ALL #(= [] %)] NONE m)
{0 {1 [[1 2 3] [4]]}, 2 [[5 6]]}

sophiago13:04:56

Oh wait. You're filtering empty vectors inside the values. I was thinking that would filter values that were empty vectors.

nathanmarz13:04:10

if you want to filter the direct values of the maps then just remove the ALL

nathanmarz13:04:48

you can also do (setval [LEAVES (continue-then-stay ALL) #(= [] %)] NONE m) to remove empty vectors from inside the map values and then remove key/value pairs where the value is []

sophiago13:04:44

Ah, I see. I just looked back at the docs. Since I'm already selecting for leaves of the maps that means ALL would go inside any collections present in the values. I assumed it meant "apply this to all leaves."

sophiago13:04:39

Yup, looks good now. Thanks!

nathanmarz15:04:58

@teng srange navigates you to a sequence, so navigating to a keyword from there doesn't make sense

nathanmarz15:04:21

I think you want: (setval [:educations (nthpath 1) :major-name] "C" data)

tengstrand15:04:45

@nathanmarz That worked, thanks! 🙂

Al Baker23:04:00

@nathanmarz so in the crazy nested structure of {:id "blah :children [{:id "blah2 :children [ .. ]]} it looks like a (select-first (recursive-path [] p [(walker (fn [x] ... match an id ...) STAY]) tree) will grab any intermediate node in that structure (and halt with the STAY) is that right?

nathanmarz23:04:00

@albaker it'll grab the first node it encounters

nathanmarz23:04:29

fyi that path isn't recursive so no reason to use recursive-path

nathanmarz23:04:43

and no reason to have the STAY after walker

Al Baker23:04:06

ah, so the walker will depth first down through w/o a recursive path, and select-first makes STAY redundant? I'm still wrapping my head around paths