Hi,
So I’m new to Elixir and I’m struggling with a recursion question. I have a tree structure (of structs, with ordered lists of children), where each node has a single parent and many children. it can be nested to an arbitrary depth.
tree = %{
id: "a",
children: [
%{
id: "one",
children: [
%{
id: "two"
}
]
},
%{
id: "three",
children: [
%{
id: "four"
},
%{
id: "five"
},
]
},
]
}
I’m trying to write a recursive function that will build an access key to a given node, identified by its ID.
Tree.path_to(tree, id, path \\ [])
``
So for example id "five", would return the following, which I can then use with the kernel's get_in and update_in functions.
[:children, Acess.to(1), :children, Access.to(1)]
I'm just too new to Elixir (and functional programming in general) to work it out so any help would be appreciated!