Modifying internal fields inside a nested hierarchy

there’s a lot of ways to do it… It’s not fun unless this is how your brain works! I wrote a decision tree method like this and it was hideously slow, although elegant via LOC. Julia just doesn’t like function calls on deeply recursive structs :/. I think the tidy solution is to break out the structure into a graph where each node is the same type for traversing the hierarchical mess, and has pointers to the actual object which is in some sort of a hashed list or something. I’d love to hear a counter argument to that, because this has befuddled me!

Anyways, an easy way, without restructuring things, would be to write a recursive function that scans a struct for depth and type and modifies as it goes. You can make a modify function that traverse the nodes recursively or using a while loop or whatever, checks the reference state modifies in place and keeps going. Maybe something like this(not real code)? dunno

fn = x -> istype(x, Array) ? push!(x, "123") : x

function modify(NestedMess::Any, fn) 
  if terminal node
         fn(node)
         return nothing
   else  
         modify.(NestedMess, fn)
    end
end

The alternative is to know exactly where you wish to modify certain things in the struct (not so fun).