Interesting idea, although I don't know if it needs to be a primitive. The os.tree function in #Python does this for file systems and, as a model, could be used as the basis for other kinds of tree structures.
> Programming languages should have a tree traversal primitive. https://blog.tylerglaiel.com/p/programming-languages-should-have
